diff --git a/src/appfinder-window.c b/src/appfinder-window.c index 211aa4f..9f83ea8 100644 --- a/src/appfinder-window.c +++ b/src/appfinder-window.c @@ -117,6 +117,7 @@ static gint xfce_appfinder_window_sort_items (GtkTreeMo GtkTreeIter *b, gpointer data); static gboolean xfce_appfinder_should_sort_icon_view (void); +static gchar ** xfce_appfinder_parse_envp (gchar **cmd); struct _XfceAppfinderWindowClass { @@ -1769,12 +1770,29 @@ xfce_appfinder_window_execute_command (const gchar *text, if (IS_STRING (text)) { + gchar **argv; + gchar **envp; + /* expand variables */ expanded = xfce_expand_variables (text, NULL); /* spawn the command */ APPFINDER_DEBUG ("spawn \"%s\"", expanded); - succeed = xfce_spawn_command_line_on_screen (screen, expanded, FALSE, FALSE, error); + + envp = g_get_environ (); + envp = xfce_appfinder_parse_envp (&expanded); + + if (G_UNLIKELY (!g_shell_parse_argv (expanded, NULL, &argv, error))) + goto cleanup; + + succeed = xfce_spawn_on_screen (screen, NULL, argv, envp, + G_SPAWN_SEARCH_PATH, FALSE, + gtk_get_current_event_time (), NULL, + error); + + cleanup: + g_strfreev (argv); + g_strfreev (envp); g_free (expanded); } @@ -2001,3 +2019,39 @@ xfce_appfinder_should_sort_icon_view (void) gtk_get_micro_version () >= 22 && gtk_get_micro_version () >= 27; } + + + +static gchar ** +xfce_appfinder_parse_envp (gchar **cmd) +{ + gchar **vars = g_strsplit (*cmd, " ", -1); + gchar **envp = g_get_environ (); + gint offset = 0; + + for (gint n = 0; vars[n] != NULL; ++n) + { + gchar *index = g_strrstr (vars[n], "="); + + if (index == NULL) + break; + + offset += strlen (vars[n]); + + gchar *var = g_strndup (vars[n], index - vars[n]); + gchar *val = g_strdup (index + 1); + + envp = g_environ_setenv (envp, var, val, TRUE); + } + + if (offset > 0) + { + gchar *temp = g_strdup (*cmd + offset + 1); + g_free (*cmd); + *cmd = temp; + } + + g_strfreev (vars); + + return envp; +}