614f1d6268
The initial working directory of a new window may be set by a `-cd directory` option. However, the `-cd directory` option is not capable of handling paths with spaces when used via wctl. 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: <snip> % 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 <snap> The following invocation fails as well: <snip> % window -cd '/tmp/path with space' % pwd /tmp/path with space <snap> After applying the patch the above sequences work as expected, opening a window running rc with the working directory set to '/tmp/path with space'.
105 lines
1.9 KiB
Bash
Executable file
105 lines
1.9 KiB
Bash
Executable file
#!/bin/rc
|
|
# window [many options] cmd [arg...] - create new window and run cmd in it
|
|
rfork e
|
|
|
|
cmd=()
|
|
spec=()
|
|
wdir=()
|
|
wpid=()
|
|
mflag=()
|
|
xflag=()
|
|
argv0=$0
|
|
|
|
if(~ $1 *[0-9][' ,'][0-9]*){
|
|
# old syntax: '100 100 200 200' or '100,100,200,200'
|
|
spec=(-r `{echo $1 | sed 's/,/ /g'})
|
|
shift
|
|
mflag=1
|
|
}
|
|
if not {
|
|
while(~ $1 -* && ~ $#xflag 0)
|
|
switch($1){
|
|
case -hide -scroll -noscroll
|
|
spec=($spec $1)
|
|
shift
|
|
case -dx -dy -minx -miny -maxx -maxy
|
|
spec=($spec $1 $2)
|
|
shift 2
|
|
case -r
|
|
spec=($spec $1 $2 $3 $4 $5)
|
|
shift 5
|
|
case -cd
|
|
wdir=$2
|
|
shift 2
|
|
case -pid
|
|
wpid=$2
|
|
shift 2
|
|
case -m
|
|
mflag=1
|
|
shift
|
|
case -x
|
|
xflag=1
|
|
shift
|
|
case *
|
|
echo usage: $argv0 '[ -m ] [ -r minx miny maxx maxy ]' \
|
|
'[ -dx n ] [ -dy n ] [ -minx n ] [ -miny n ] [ -maxx n ] [ -maxy n ]' \
|
|
'[ -cd dir ] [ -hide ] [ -scroll ] [ -noscroll ] [ cmd arg ... ]' >[1=2]
|
|
exit usage
|
|
}
|
|
}
|
|
|
|
if(~ $#* 0) cmd=rc
|
|
if not cmd=$*
|
|
|
|
if(~ $#xflag 1){
|
|
echo -n `{basename $cmd(1)} >/dev/label >[2]/dev/null
|
|
rm -f /env/^(cmd spec wdir wpid mflag xflag argv0)
|
|
exec $cmd
|
|
exit exec
|
|
}
|
|
|
|
if(~ $#mflag 1) {
|
|
if(~ $wsys ''){
|
|
echo $argv0: '$wsys' not defined >[1=2]
|
|
exit bad
|
|
}
|
|
|
|
{
|
|
rfork n
|
|
|
|
if(~ $wsys /srv/*){
|
|
if(~ $#wpid 0)
|
|
wpid=`{cat /dev/ppid}
|
|
spec=($spec -pid $wpid)
|
|
}
|
|
if(~ $#wdir 0){
|
|
wdir=`{pwd}
|
|
}
|
|
if not {
|
|
builtin cd $wdir
|
|
}
|
|
spec=($spec -cd $wdir)
|
|
|
|
{unmount /mnt/acme /dev; unmount $wsys /dev} >[2]/dev/null
|
|
if(mount $wsys /mnt/wsys 'new '$"spec){
|
|
bind -b /mnt/wsys /dev
|
|
exec $argv0 -x $cmd </dev/cons >/dev/cons >[2]/dev/cons
|
|
}
|
|
}&
|
|
exit ''
|
|
}
|
|
if not {
|
|
if(~ $wctl ''){
|
|
if(test -f /dev/wctl) wctl=/dev/wctl
|
|
if not if(test -f /mnt/term/dev/wctl) wctl=/mnt/term/dev/wctl
|
|
if not if(test -r /mnt/term/env/wctl) wctl=/mnt/term^`{cat /mnt/term/env/wctl}
|
|
if not {
|
|
echo $argv0: '$wctl' not defined >[1=2]
|
|
exit bad
|
|
}
|
|
}
|
|
|
|
if(! ~ $#wdir 0)
|
|
spec=($spec -cd `{a=$wdir whatis a|sed 's!^a=!!;q'})
|
|
echo new $spec $argv0 -x $cmd >>$wctl
|
|
}
|