[console] application: Treat a single argument to -e as --command



commit 33db8d5e574bc1fcab27145e7683e1b7aa13b25d
Author: Simon McVittie <smcv debian org>
Date:   Sat Apr 9 17:32:11 2022 +0100

    application: Treat a single argument to -e as --command
    
    This matches what xterm does: if the argument would be valid as argv[0],
    execute it directly, or if not, try parsing it with a shell instead.
    
    Signed-off-by: Simon McVittie <smcv debian org>

 src/kgx-application.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 08d2b30..753f37e 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -443,8 +443,14 @@ kgx_application_local_command_line (GApplication   *app,
        *     kgx -T "Directory listing" -e ls -al /
        *
        * passes "-al" to ls instead of trying to parse them as kgx
-       * options. To do this, turn -e into the "--" pseudo-argument. */
-      (*arguments)[i][1] = '-';
+       * options. To do this, turn -e into the "--" pseudo-argument -
+       * unless there is exactly one argument following it, in which
+       * case leave it as -e, which the GOptionContext will treat
+       * like --command. */
+      if (!((*arguments)[i + 1] != NULL && (*arguments)[i + 2] == NULL)) {
+        (*arguments)[i][1] = '-';
+      }
+
       break;
     } else if (strcmp ((*arguments)[i], "--") == 0) {
       /* Don't continue to edit arguments after the -- separator,
@@ -761,7 +767,7 @@ static GOptionEntry entries[] = {
   },
   {
     "command",
-    0,
+    'e',
     0,
     G_OPTION_ARG_FILENAME,
     NULL,


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