You need to sign in or sign up before continuing.
Commit 96c38db4 authored by Victor Ananjevsky's avatar Victor Ananjevsky

add --use-interp option

parent dcc8af38
......@@ -166,6 +166,10 @@ Don't close dialog if \fIEscape\fP was pressed.
.B \-\-always-print-result
Print result for any of the return codes. This option doesn't work if timeout was reached or \fIEscape\fP was pressed.
.TP
.B \-\-use-interp=\fI[INTERP]\fP
All commands runs unter specified interpreter. Default is \fIbash -c '%s'\fP. This option can reduse quoting in commands. If \fI%s\fP is specified, it will be replaced by the command.
Otherwise command will be appended to the end of command line.
.TP
.B \-\-borders=\fINUM\fP
Set dialog window borders.
.TP
......
......@@ -48,7 +48,7 @@ drop_data_cb (GtkWidget * w, GdkDragContext * dc, gint x, gint y,
action = g_strdup_printf (options.common_data.command, dstr);
else
action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
g_spawn_command_line_async (action, NULL);
run_command_async (action);
g_free (action);
}
else
......@@ -77,7 +77,8 @@ drop_data_cb (GtkWidget * w, GdkDragContext * dc, gint x, gint y,
else
action = g_strdup_printf ("%s %s", options.common_data.command, arg);
g_free (arg);
g_spawn_command_line_async (action, NULL);
run_command_async (action);
g_free (action);
}
else
......
......@@ -373,7 +373,7 @@ button_clicked_cb (GtkButton * b, gpointer data)
gchar *data;
gint exit = 1;
GString *cmd = expand_action (action + 1);
g_spawn_command_line_sync (cmd->str, &data, NULL, &exit, NULL);
exit = run_command_sync (cmd->str, &data);
if (exit == 0)
{
guint i = 0;
......@@ -402,7 +402,7 @@ button_clicked_cb (GtkButton * b, gpointer data)
else
{
GString *cmd = expand_action (action);
g_spawn_command_line_async (cmd->str, NULL);
run_command_async (cmd->str);
g_string_free (cmd, TRUE);
}
}
......
......@@ -121,7 +121,7 @@ policy_cb (WebKitWebView *v, WebKitPolicyDecision *pd, WebKitPolicyDecisionType
g_setenv ("YAD_HTML_STATE", v2, TRUE);
cmd = g_strdup_printf ("%s '%s'", options.html_data.uri_cmd, uri);
g_spawn_command_line_sync (cmd, NULL, NULL, &status, NULL);
status = run_command_sync (cmd, NULL);
g_free (cmd);
g_unsetenv ("YAD_HTML_BUTTON");
......
......@@ -134,14 +134,12 @@ activate_cb (GtkWidget * view, GtkTreePath * path, gpointer data)
{
if (in_term)
{
gchar *tcmd;
tcmd = g_strdup_printf (options.icons_data.term, cmd);
g_spawn_command_line_async (tcmd, NULL);
gchar *tcmd = g_strdup_printf (options.icons_data.term, cmd);
run_command_async (tcmd);
g_free (tcmd);
}
else
g_spawn_command_line_async (cmd, NULL);
run_command_async (cmd);
}
}
......
......@@ -756,7 +756,7 @@ double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column
gchar *data = NULL;
gint exit;
g_spawn_command_line_sync (cmd + 1, &data, NULL, &exit, NULL);
exit = run_command_sync (cmd + 1, &data);
if (exit == 0)
{
gint i;
......@@ -774,7 +774,7 @@ double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column
g_free (data);
}
else
g_spawn_command_line_async (cmd, NULL);
run_command_async (cmd);
g_free (cmd);
}
......@@ -832,7 +832,7 @@ select_cb (GtkTreeSelection *sel, gpointer data)
cmd = g_strdup_printf ("%s %s", options.list_data.select_action, args);
g_free (args);
g_spawn_command_line_async (cmd, NULL);
run_command_async (cmd);
g_free (cmd);
}
......@@ -870,7 +870,7 @@ add_row_cb (GtkMenuItem *item, gpointer data)
/* run command */
cmd = g_strdup_printf ("%s add", options.list_data.row_action);
g_spawn_command_line_sync (cmd, &out, NULL, &exit, NULL);
exit = run_command_sync (cmd, &out);
g_free (cmd);
if (exit == 0)
{
......@@ -913,7 +913,7 @@ edit_row_cb (GtkMenuItem *item, gpointer data)
args = get_data_as_string (&iter);
cmd = g_strdup_printf ("%s edit %s", options.list_data.row_action, args);
g_free (args);
g_spawn_command_line_sync (cmd, &out, NULL, &exit, NULL);
exit = run_command_sync (cmd, &out);
g_free (cmd);
if (exit == 0)
{
......@@ -956,7 +956,7 @@ del_row_cb (GtkMenuItem *item, gpointer data)
args = get_data_as_string (&iter);
cmd = g_strdup_printf ("%s del %s", options.list_data.row_action, args);
g_free (args);
g_spawn_command_line_sync (cmd, NULL, NULL, &exit, NULL);
exit = run_command_sync (cmd, NULL);
g_free (cmd);
if (exit == 0)
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
......
......@@ -99,7 +99,7 @@ static void
btn_cb (GtkWidget *b, gchar *cmd)
{
if (cmd)
g_spawn_command_line_async (cmd, NULL);
run_command_async (cmd);
else
{
gint resp = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "resp"));
......
......@@ -165,7 +165,7 @@ activate_cb (GtkWidget * widget, YadData * data)
if (g_ascii_strcasecmp (action, "menu") == 0)
popup_menu_cb (GTK_STATUS_ICON (widget), 1, GDK_CURRENT_TIME, data);
else
g_spawn_command_line_async (action, NULL);
run_command_async (action);
}
return TRUE;
......@@ -199,7 +199,7 @@ popup_menu_item_activate_cb (GtkWidget * w, gpointer data)
gtk_main_quit ();
}
else
g_spawn_command_line_async (cmd, NULL);
run_command_async (cmd);
}
}
......
......@@ -57,6 +57,7 @@ static gboolean set_scroll_policy (const gchar *, const gchar *, gpointer, GErro
#if GLIB_CHECK_VERSION(2,30,0)
static gboolean set_size_format (const gchar *, const gchar *, gpointer, GError **);
#endif
static gboolean set_interp (const gchar *, const gchar *, gpointer, GError **);
static gboolean about_mode = FALSE;
static gboolean version_mode = FALSE;
......@@ -141,6 +142,8 @@ static GOptionEntry general_options[] = {
N_("Dialog text can be selected"), NULL },
{ "keep-icon-size", 0, 0, G_OPTION_ARG_NONE, &options.data.keep_icon_size,
N_("Don't scale icons"), NULL },
{ "use-interp", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_interp,
N_("Run commands under specified interpreter (default: bash -c '%s')"), N_("CMD") },
/* window settings */
{ "sticky", 0, 0, G_OPTION_ARG_NONE, &options.data.sticky,
N_("Set window sticky"), NULL },
......@@ -1254,6 +1257,17 @@ set_size_format (const gchar * option_name, const gchar * value, gpointer data,
}
#endif
static gboolean
set_interp (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
options.data.use_interp = TRUE;
if (value)
options.data.interp = g_strdup (value);
return TRUE;
}
#ifndef G_OS_WIN32
static gboolean
set_xid_file (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
......@@ -1486,6 +1500,8 @@ yad_options_init (void)
options.data.selectable_labels = FALSE;
options.data.keep_icon_size = FALSE;
options.data.def_resp = YAD_RESPONSE_OK;
options.data.use_interp = FALSE;
options.data.interp = "bash -c '%s'";
/* Initialize window options */
options.data.sticky = FALSE;
......
......@@ -178,7 +178,7 @@ tag_event_cb (GtkTextTag * tag, GObject * obj, GdkEvent * ev, GtkTextIter * iter
#endif
g_free (url);
g_spawn_command_line_async (cmdline, NULL);
run_command_async (cmdline);
g_free (cmdline);
return TRUE;
......
......@@ -612,6 +612,60 @@ print_bool_val (gboolean val)
return ret;
}
gint
run_command_sync (gchar *cmd, gchar **out)
{
gint ret = 0;
gchar *full_cmd = NULL;
GError *err = NULL;
if (options.data.use_interp)
{
if (g_strstr_len (options.data.interp, -1, "%s") != NULL)
full_cmd = g_strdup_printf (options.data.interp, cmd);
else
full_cmd = g_strdup_printf ("%s %s", options.data.interp, cmd);
}
else
full_cmd = g_strdup (cmd);
if (!g_spawn_command_line_sync (full_cmd, out, NULL, &ret, &err))
{
if (options.debug)
g_printerr ("YAD: WARNING: Run command failed: %s", err->message);
g_error_free (err);
}
g_free (full_cmd);
return ret;
}
void
run_command_async (gchar *cmd)
{
gchar *full_cmd = NULL;
GError *err = NULL;
if (options.data.use_interp)
{
if (g_strstr_len (options.data.interp, -1, "%s") != NULL)
full_cmd = g_strdup_printf (options.data.interp, cmd);
else
full_cmd = g_strdup_printf ("%s %s", options.data.interp, cmd);
}
else
full_cmd = g_strdup (cmd);
if (!g_spawn_command_line_async (full_cmd, &err))
{
if (options.debug)
g_printerr ("YAD: WARNING: Run command failed: %s", err->message);
g_error_free (err);
}
g_free (full_cmd);
}
#ifdef HAVE_SPELL
void
show_langs ()
......
......@@ -233,6 +233,8 @@ typedef struct {
gboolean keep_icon_size;
GtkButtonBoxStyle buttons_layout;
gint def_resp;
gboolean use_interp;
gchar *interp;
/* window settings */
gboolean sticky;
gboolean fixed;
......@@ -652,6 +654,9 @@ void parse_geometry ();
gboolean get_bool_val (gchar *str);
gchar *print_bool_val (gboolean val);
gint run_command_sync (gchar *cmd, gchar **out);
void run_command_async (gchar *cmd);
#ifdef HAVE_SPELL
void show_langs ();
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment