cwd in B2-B1 chord
The following patch changes the B2-B1 chord behavior so that the
working directory of the command is the same as the pane containing
the command's argument, not the working directory of the pane
containing the text of the command. This comes in handy when using
"guide" files (files containing frequently-used commands for various
contexts like C code, mail, etc.).
Even better, guide files might be guide directories containing
wily-aware shell scripts, so the directory of the *command* gets added
to PATH when the command gets executed. I'm a little concerned about
the security of this, but it seems like the "right" thing to do.
--- 1.2 1995/08/31 21:25:12
+++ external.c 1995/09/01 01:09:47
@@ -113,7 +113,12 @@
ulong key;
ulong ckey; /* key for commands */
- text2label(t,label);
+ /* use the directory of the argument for the cwd, if present */
+ if (arg && last_selection)
+ text2label(last_selection, label);
+ else
+ text2label(t, label);
+
DPRINT("doexec [%s,%s,%s]\n", label,cmd,arg?arg:"NULL");
if (pipe(output)) {
@@ -166,7 +171,7 @@
} else {
int devnull;
char cmdbuf[MAXPATH];
- char lblbuf[MAXPATH];
+ char envbuf[10 * MAXPATH];
char *shell;
/* any errors in here, just die and we'll get collected by
parent */
@@ -187,17 +192,28 @@
* if we can work out a directory, try to change to it,
* If we fail, we don't mind much.
*/
- if (!context2dir(label, dir)) {
- if (chdir(dir)) {
- diag ("chdir %s", dir);
- }
- }
+ if (chdir(dir) < 0)
+ diag ("chdir %s", dir);
/* Set up environment */
- sprintf(lblbuf, "WILYLABEL=%s", label);
- if(putenv(lblbuf))
- diag("putenv %s", lblbuf);
+ snprintf(envbuf, sizeof envbuf, "WILYLABEL=%s", label);
+ if (putenv(envbuf))
+ diag("putenv %s", envbuf);
+
+ /* The path needs to include the directory containing
+ the text of the command. No big deal if it's not there.
+ OR IS THIS A SECURITY PROBLEM? It sure makes
+ sense to have a "mail" directory containing wily mail
+ commands, for instance.
+ */
+ text2label(t, label);
+ if (context2dir(label, dir) != 0) {
+ snprintf(envbuf, sizeof envbuf, "PATH=%s:%s",
+ dir, getenv("PATH"));
+ if (putenv(envbuf) != 0)
+ diag("putenv %s", envbuf);
+ }
/* find the shell */
shell = (char*)getenv("SHELL");
if(!shell) {
Partial thread listing: