Josh and I were discussing this over IRC. Here's an alternative patch I
came up with. It relies on the shell that executes st to parse the
arguments, so you can't run a command like st -e "touch arst", you have
to run st -e touch arst. This also means you can't have any st arguments
after the -e because they'll all be included in the command to run.
xterm also has this restriction, although for some reason it's "smart"
enough to run xterm -e "touch arst" correctly.

On 11/26/2010 05:57 PM, Josh Rickmar wrote:
> Here's a quick fix to pass the opt_cmd to $SHELL -c, which fixes a
> bug where you couldn't call -e with a command with spaces (arguments
> to that command).
> 
> I earlier tried to pass the command directly to execvp() by using
> strsep to set args, but the code turned out to be far too complex
> (I think).
diff -r c4ef5533a330 st.c
--- a/st.c      Fri Nov 26 22:12:54 2010 +0100
+++ b/st.c      Fri Nov 26 18:33:02 2010 -0500
@@ -247,7 +247,7 @@
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
-static char *opt_cmd   = NULL;
+static char **opt_cmd  = NULL;
 static char *opt_title = NULL;
 static char *opt_class = NULL;
 
@@ -546,12 +546,11 @@
 void
 execsh(void) {
        char *args[] = {getenv("SHELL"), "-i", NULL};
+       putenv("TERM="TNAME);
        if(opt_cmd)
-               args[0] = opt_cmd, args[1] = NULL;
+               execvp(opt_cmd[0], opt_cmd);
        else
-               DEFAULT(args[0], SHELL);
-       putenv("TERM="TNAME);
-       execvp(args[0], args);
+               execvp(args[0], args);
 }
 
 void 
@@ -1845,12 +1844,13 @@
                        if(++i < argc) opt_class = argv[i];
                        break;
                case 'e':
-                       if(++i < argc) opt_cmd = argv[i];
+                       if(++i < argc) opt_cmd = &argv[i];
                        break;
                case 'v':
                default:
                        die(USAGE);
                }
+               if (opt_cmd) break;
        }
        setlocale(LC_CTYPE, "");
        tnew(80, 24);

Reply via email to