From: Igor Böhm Date: Mon, 29 Nov 2021 00:06:45 +0000 Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window The initial working directory of the new window may be set by a `-cd directory` option. However, the `-cd directory` option is not capable of handling paths with spaces. To enable paths with spaces the function /sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted directory paths. Before applying the patch the following will fail to open a new window by writing to /dev/wctl: % rio -i window % mkdir '/tmp/path with space' % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl % pwd /tmp/path with space The following invocation fails as well: % window -cd '/tmp/path with space' % pwd /tmp/path with space After applying the patch the above sequences work as expected, opening a window running rc and the working directory set to '/tmp/path with space'. --- diff 78c7ad88ffbfbd2b7a7269d863e5f4be7535b566 06623a45c7101085ce651a92ff8b952fe239eaac --- a/rc/bin/window Fri Nov 26 22:47:15 2021 +++ b/rc/bin/window Mon Nov 29 01:06:45 2021 @@ -100,6 +100,6 @@ } if(! ~ $#wdir 0) - spec=($spec -cd $wdir) + spec=($spec -cd `{a=$wdir whatis a|sed 's!^a=!!;q'}) echo new $spec $argv0 -x $cmd >>$wctl } --- a/sys/src/cmd/rio/wctl.c Fri Nov 26 22:47:15 2021 +++ b/sys/src/cmd/rio/wctl.c Mon Nov 29 01:06:45 2021 @@ -203,7 +203,7 @@ parsewctl(char **argp, Rectangle r, Rectangle *rp, int *pidp, int *idp, int *hiddenp, int *scrollingp, char **cdp, char *s, char *err) { int cmd, param, xy, sign; - char *t; + char *f[2], *t; *pidp = 0; *hiddenp = 0; @@ -252,10 +252,13 @@ s++; if(param == Cd){ *cdp = s; - while(*s && !isspace(*s)) - s++; - if(*s != '\0') - *s++ = '\0'; + gettokens(*cdp, f, nelem(f), " \t\r\n\v\f"); + s += strlen(*cdp); + if((*cdp)[0] == '\'' && s[-1] == '\''){ + /* drop quotes */ + *cdp += 1; + s[-1] = '\0'; + } continue; } sign = 0;