[Xfce4-commits] [apps/xfce4-terminal] 01/01: Add "Run custom command instead of shell" feature
noreply at xfce.org
noreply at xfce.org
Sun Dec 18 17:07:12 CET 2016
This is an automated email from the git hooks/post-receive script.
f2404 pushed a commit to branch master
in repository apps/xfce4-terminal.
commit 9c168d3a8dc8741cdb7368aed6b86bff925fb5e9
Author: Igor <f2404 at yandex.ru>
Date: Sun Dec 18 19:05:59 2016 +0300
Add "Run custom command instead of shell" feature
This is sometimes more handy than using -e/-x command line options.
Implements https://bugzilla.xfce.org/show_bug.cgi?id=13236
---
terminal/terminal-preferences-dialog.c | 30 ++++++++++++
terminal/terminal-preferences.c | 22 +++++++++
terminal/terminal-preferences.glade | 58 +++++++++++++++++++++++
terminal/terminal-screen.c | 86 ++++++++++++++++++++--------------
4 files changed, 161 insertions(+), 35 deletions(-)
diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index 4bad43b..1cf0882 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -64,6 +64,8 @@ static void terminal_preferences_dialog_background_set (GtkFileChooserButton
TerminalPreferencesDialog *dialog);
static void terminal_preferences_dialog_encoding_changed (GtkComboBox *combobox,
TerminalPreferencesDialog *dialog);
+static void terminal_preferences_dialog_custom_command (GtkWidget *button,
+ TerminalPreferencesDialog *dialog);
static void terminal_preferences_dialog_scroll_unlimited (GtkWidget *button,
TerminalPreferencesDialog *dialog);
static void terminal_preferences_dialog_font_use_system (GtkWidget *button,
@@ -140,6 +142,7 @@ terminal_preferences_dialog_init (TerminalPreferencesDialog *dialog)
gchar *current;
GtkTreeIter current_iter;
const gchar *props_active[] = { "title-mode", "command-login-shell",
+ "run-custom-command",
"scrolling-on-output", "scrolling-on-keystroke",
"scrolling-bar", "scrolling-unlimited",
"misc-cursor-shape", "misc-cursor-blinks",
@@ -235,12 +238,21 @@ error:
/* other properties */
BIND_PROPERTIES ("font-name", "font-name");
BIND_PROPERTIES ("title-initial", "text");
+ BIND_PROPERTIES ("custom-command", "text");
BIND_PROPERTIES ("word-chars", "text");
BIND_PROPERTIES ("scrolling-lines", "value");
BIND_PROPERTIES ("tab-activity-timeout", "value");
BIND_PROPERTIES ("background-darkness", "value");
BIND_PROPERTIES ("background-image-shading", "value");
+ /* run custom command button */
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "run-custom-command");
+ terminal_return_if_fail (G_IS_OBJECT (object));
+ g_signal_connect (G_OBJECT (object), "realize",
+ G_CALLBACK (terminal_preferences_dialog_custom_command), dialog);
+ g_signal_connect (G_OBJECT (object), "clicked",
+ G_CALLBACK (terminal_preferences_dialog_custom_command), dialog);
+
/* unlimited scrollback button */
object = gtk_builder_get_object (GTK_BUILDER (dialog), "scrolling-unlimited");
terminal_return_if_fail (G_IS_OBJECT (object));
@@ -953,6 +965,24 @@ terminal_preferences_dialog_encoding_changed (GtkComboBox *combobo
static void
+terminal_preferences_dialog_custom_command (GtkWidget *button,
+ TerminalPreferencesDialog *dialog)
+{
+ GObject *object;
+ gboolean run_custom_command;
+
+ terminal_return_if_fail (TERMINAL_IS_PREFERENCES_DIALOG (dialog));
+ terminal_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
+
+ run_custom_command = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "custom-command");
+ terminal_return_if_fail (G_IS_OBJECT (object));
+ g_object_set (G_OBJECT (object), "sensitive", run_custom_command, NULL);
+}
+
+
+
+static void
terminal_preferences_dialog_scroll_unlimited (GtkWidget *button,
TerminalPreferencesDialog *dialog)
{
diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index 30ad359..99ff5ae 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -62,6 +62,8 @@ enum
PROP_COLOR_BOLD_USE_DEFAULT,
PROP_COLOR_PALETTE,
PROP_COMMAND_LOGIN_SHELL,
+ PROP_RUN_CUSTOM_COMMAND,
+ PROP_CUSTOM_COMMAND,
PROP_DROPDOWN_ANIMATION_TIME,
PROP_DROPDOWN_KEEP_OPEN_DEFAULT,
PROP_DROPDOWN_KEEP_ABOVE,
@@ -528,6 +530,26 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
+ * TerminalPreferences:run-custom-command:
+ **/
+ preferences_props[PROP_RUN_CUSTOM_COMMAND] =
+ g_param_spec_boolean ("run-custom-command",
+ NULL,
+ "RunCustomCommand",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * TerminalPreferences:custom-command:
+ **/
+ preferences_props[PROP_CUSTOM_COMMAND] =
+ g_param_spec_string ("custom-command",
+ NULL,
+ "CustomCommand",
+ "",
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
* TerminalPreferences:dropdown-animation-time:
**/
preferences_props[PROP_DROPDOWN_ANIMATION_TIME] =
diff --git a/terminal/terminal-preferences.glade b/terminal/terminal-preferences.glade
index faa85a2..4def76b 100644
--- a/terminal/terminal-preferences.glade
+++ b/terminal/terminal-preferences.glade
@@ -411,6 +411,64 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="run-custom-command">
+ <property name="label" translatable="yes">Run a _custom command instead of my shell</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Select this option to force Terminal to run custom command instead of your shell when you open new terminals.</property>
+ <property name="halign">start</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="label56">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">C_ustom command:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="custom-command">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="invisible_char">•</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index e86dc4c..c2069d5 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -582,7 +582,9 @@ terminal_screen_get_child_command (TerminalScreen *screen,
struct passwd *pw;
const gchar *shell_name;
const gchar *shell_fullpath = NULL;
+ gchar *custom_command = NULL;
gboolean command_login_shell;
+ gboolean run_custom_command;
guint i;
const gchar *shells[] = { "/bin/sh",
"/bin/bash", "/usr/bin/bash",
@@ -599,68 +601,82 @@ terminal_screen_get_child_command (TerminalScreen *screen,
}
else
{
- /* use the SHELL environement variable if we're in
- * non-setuid mode and the path is executable */
- if (geteuid () == getuid ()
- && getegid () == getgid ())
+ g_object_get (G_OBJECT (screen->preferences),
+ "command-login-shell", &command_login_shell,
+ "run-custom-command", &run_custom_command,
+ NULL);
+
+ if (run_custom_command)
{
- shell_fullpath = g_getenv ("SHELL");
- if (shell_fullpath != NULL
- && g_access (shell_fullpath, X_OK) != 0)
- shell_fullpath = NULL;
+ /* use custom command specified in preferences */
+ g_object_get (G_OBJECT (screen->preferences),
+ "custom-command", &custom_command,
+ NULL);
+ shell_fullpath = custom_command;
}
-
- if (shell_fullpath == NULL)
+ else
{
- pw = getpwuid (getuid ());
- if (pw != NULL
- && pw->pw_shell != NULL
- && g_access (pw->pw_shell, X_OK) == 0)
+ /* use the SHELL environement variable if we're in
+ * non-setuid mode and the path is executable */
+ if (geteuid () == getuid ()
+ && getegid () == getgid ())
{
- /* set the shell from the password database */
- shell_fullpath = pw->pw_shell;
+ shell_fullpath = g_getenv ("SHELL");
+ if (shell_fullpath != NULL
+ && g_access (shell_fullpath, X_OK) != 0)
+ shell_fullpath = NULL;
}
- else
+
+ if (shell_fullpath == NULL)
{
- /* lookup a good fallback */
- for (i = 0; i < G_N_ELEMENTS (shells); i++)
+ pw = getpwuid (getuid ());
+ if (pw != NULL
+ && pw->pw_shell != NULL
+ && g_access (pw->pw_shell, X_OK) == 0)
{
- if (access (shells [i], X_OK) == 0)
+ /* set the shell from the password database */
+ shell_fullpath = pw->pw_shell;
+ }
+ else
+ {
+ /* lookup a good fallback */
+ for (i = 0; i < G_N_ELEMENTS (shells); i++)
{
- shell_fullpath = shells [i];
- break;
+ if (access (shells [i], X_OK) == 0)
+ {
+ shell_fullpath = shells [i];
+ break;
+ }
}
- }
- if (G_UNLIKELY (shell_fullpath == NULL))
- {
- /* the system is truly broken */
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
- _("Unable to determine your login shell."));
- return FALSE;
- }
+ if (G_UNLIKELY (shell_fullpath == NULL))
+ {
+ /* the system is truly broken */
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
+ _("Unable to determine your login shell."));
+ return FALSE;
+ }
+ }
}
}
terminal_assert (shell_fullpath != NULL);
shell_name = strrchr (shell_fullpath, '/');
-
if (shell_name != NULL)
++shell_name;
else
shell_name = shell_fullpath;
*command = g_strdup (shell_fullpath);
- g_object_get (G_OBJECT (screen->preferences),
- "command-login-shell", &command_login_shell,
- NULL);
-
*argv = g_new (gchar *, 2);
if (command_login_shell)
(*argv)[0] = g_strconcat ("-", shell_name, NULL);
else
(*argv)[0] = g_strdup (shell_name);
(*argv)[1] = NULL;
+
+ if (custom_command != NULL)
+ g_free (custom_command);
}
return TRUE;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list