2011-03-30 14:14:36 +00:00
|
|
|
#!/bin/rc
|
|
|
|
# window [many options] cmd [arg...] - create new window and run cmd in it
|
|
|
|
rfork e
|
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
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
|
2011-03-30 14:14:36 +00:00
|
|
|
shift
|
2013-12-25 00:30:43 +00:00
|
|
|
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
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
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
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
if(~ $#mflag 1) {
|
|
|
|
if(~ $wsys ''){
|
|
|
|
echo $argv0: '$wsys' not defined >[1=2]
|
|
|
|
exit bad
|
|
|
|
}
|
2011-03-30 14:14:36 +00:00
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
{
|
|
|
|
rfork n
|
|
|
|
|
|
|
|
if(~ $wsys /srv/*){
|
|
|
|
if(~ $#wpid 0)
|
|
|
|
wpid=`{cat /dev/ppid}
|
|
|
|
spec=($spec -pid $wpid)
|
|
|
|
}
|
|
|
|
if(~ $#wdir 0){
|
|
|
|
wdir=`{pwd}
|
|
|
|
}
|
2011-03-30 14:14:36 +00:00
|
|
|
if not {
|
2013-12-25 00:30:43 +00:00
|
|
|
builtin cd $wdir
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
2013-12-25 00:30:43 +00:00
|
|
|
spec=($spec -cd $wdir)
|
2011-03-30 14:14:36 +00:00
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
{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
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
|
|
|
}&
|
2020-09-16 11:12:13 +00:00
|
|
|
exit ''
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
2013-12-25 00:30:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 14:14:36 +00:00
|
|
|
|
2013-12-25 00:30:43 +00:00
|
|
|
if(! ~ $#wdir 0)
|
|
|
|
spec=($spec -cd $wdir)
|
|
|
|
echo new $spec $argv0 -x $cmd >>$wctl
|
|
|
|
}
|