[gnome-builder] shellcmd: allow shell expansion from commands



commit e9de03fb0899e077be37cadb95f2af820336571b
Author: Christian Hergert <chergert redhat com>
Date:   Sat Aug 10 13:03:22 2019 -0700

    shellcmd: allow shell expansion from commands

 src/plugins/shellcmd/gbp-shellcmd-command-provider.c |  9 +++------
 src/plugins/shellcmd/gbp-shellcmd-command.c          | 20 ++++++++++++++++----
 2 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-provider.c 
b/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
index 2babff004..184161a45 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-provider.c
@@ -65,7 +65,6 @@ gbp_shellcmd_command_provider_query_async (IdeCommandProvider  *provider,
   GbpShellcmdCommandProvider *self = (GbpShellcmdCommandProvider *)provider;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GPtrArray) ret = NULL;
-  g_autofree gchar *bash_c = NULL;
   g_autofree gchar *quoted = NULL;
   IdeContext *context;
 
@@ -85,14 +84,12 @@ gbp_shellcmd_command_provider_query_async (IdeCommandProvider  *provider,
     goto skip_commands;
 
   context = ide_workspace_get_context (workspace);
-  quoted = g_shell_quote (typed_text);
-  bash_c = g_strdup_printf ("/bin/sh -c %s", quoted);
 
   g_ptr_array_add (ret,
                    g_object_new (GBP_TYPE_SHELLCMD_COMMAND,
                                  "title", _("Run in host environment"),
                                  "subtitle", typed_text,
-                                 "command", bash_c,
+                                 "command", typed_text,
                                  "locality", GBP_SHELLCMD_COMMAND_LOCALITY_HOST,
                                  NULL));
 
@@ -102,14 +99,14 @@ gbp_shellcmd_command_provider_query_async (IdeCommandProvider  *provider,
                        g_object_new (GBP_TYPE_SHELLCMD_COMMAND,
                                      "title", _("Run in build environment"),
                                      "subtitle", typed_text,
-                                     "command", bash_c,
+                                     "command", typed_text,
                                      "locality", GBP_SHELLCMD_COMMAND_LOCALITY_BUILD,
                                      NULL));
       g_ptr_array_add (ret,
                        g_object_new (GBP_TYPE_SHELLCMD_COMMAND,
                                      "title", _("Run in runtime environment"),
                                      "subtitle", typed_text,
-                                     "command", bash_c,
+                                     "command", typed_text,
                                      "locality", GBP_SHELLCMD_COMMAND_LOCALITY_RUN,
                                      NULL));
     }
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command.c b/src/plugins/shellcmd/gbp-shellcmd-command.c
index 04e8948ee..0404ae89b 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command.c
@@ -36,8 +36,10 @@
 struct _GbpShellcmdCommand
 {
   IdeObject                   parent_instance;
+
   GbpShellcmdCommandLocality  locality;
   gint                        priority;
+
   gchar                      *id;
   gchar                      *shortcut;
   gchar                      *subtitle;
@@ -639,9 +641,11 @@ gbp_shellcmd_command_run_async (IdeCommand          *command,
                                 gpointer             user_data)
 {
   GbpShellcmdCommand *self = (GbpShellcmdCommand *)command;
+  g_autoptr(GPtrArray) with_sh = NULL;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GError) error = NULL;
   g_auto(GStrv) argv = NULL;
+  gchar **real_argv;
   gint argc = 0;
 
   g_assert (GBP_IS_SHELLCMD_COMMAND (self));
@@ -665,22 +669,30 @@ gbp_shellcmd_command_run_async (IdeCommand          *command,
       return;
     }
 
+  with_sh = g_ptr_array_new ();
+  g_ptr_array_add (with_sh, (gchar *)"/bin/sh");
+  g_ptr_array_add (with_sh, (gchar *)"-c");
+  g_ptr_array_add (with_sh, (gchar *)self->command);
+  g_ptr_array_add (with_sh, NULL);
+
+  real_argv = (gchar **)(gpointer)with_sh->pdata;
+
   switch (self->locality)
     {
     case GBP_SHELLCMD_COMMAND_LOCALITY_HOST:
-      gbp_shellcmd_command_run_host (self, argv, task);
+      gbp_shellcmd_command_run_host (self, real_argv, task);
       break;
 
     case GBP_SHELLCMD_COMMAND_LOCALITY_APP:
-      gbp_shellcmd_command_run_app (self, argv, task);
+      gbp_shellcmd_command_run_app (self, real_argv, task);
       break;
 
     case GBP_SHELLCMD_COMMAND_LOCALITY_BUILD:
-      gbp_shellcmd_command_run_build (self, argv, task);
+      gbp_shellcmd_command_run_build (self, real_argv, task);
       break;
 
     case GBP_SHELLCMD_COMMAND_LOCALITY_RUN:
-      gbp_shellcmd_command_run_runner (self, argv, task);
+      gbp_shellcmd_command_run_runner (self, real_argv, task);
       break;
 
     default:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]