1
0

window 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/rc
  2. # window [many options] cmd [arg...] - create new window and run cmd in it
  3. rfork e
  4. fn checkwsys{
  5. if(~ $wsys ''){
  6. echo 'window: $wsys not defined'
  7. exit bad
  8. }
  9. }
  10. # original version used mount to do the work
  11. fn oldway{
  12. switch($#*){
  13. case 0 1
  14. echo usage: window '''minx miny maxx maxy''' cmd args ...
  15. exit usage
  16. }
  17. checkwsys
  18. dir = /mnt/wsys
  19. srv = $wsys
  20. rfork ne
  21. {
  22. if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
  23. shift
  24. bind -b $dir /dev
  25. echo -n `{basename $1} > /dev/label >[2] /dev/null
  26. exec $* < /dev/cons > /dev/cons >[2] /dev/cons
  27. }
  28. }&
  29. }
  30. # if argument is of form '100 100 200 200' or '100,100,200,200' use old way
  31. if(~ $1 *[0-9][' ,'][0-9]*){
  32. oldway $*
  33. exit
  34. }
  35. # geometry parameters are:
  36. # -r 0 0 100 100
  37. # -dx n
  38. # -dy n
  39. # -minx n
  40. # -miny n
  41. # -maxx n
  42. # -maxy n
  43. # where n can be a number, to set the value, or +number or -number to change it
  44. # find wctl file
  45. fn getwctl{
  46. if(~ $wctl ''){
  47. if(test -f /dev/wctl) echo /dev/wctl
  48. if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
  49. if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
  50. if not {
  51. echo window: '$wctl' not defined >[1=2]
  52. exit usage
  53. }
  54. }
  55. if not echo $wctl
  56. }
  57. # use mount to make local window
  58. if(~ $1 -m){
  59. shift
  60. checkwsys
  61. dir = /mnt/wsys
  62. srv = $wsys
  63. rfork ne
  64. {
  65. unmount /mnt/acme /dev >[2]/dev/null
  66. if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
  67. bind -b $dir /dev
  68. # toss geometry parameters to find command
  69. while(~ $1 -*)
  70. switch($1){
  71. case -dx -dy -minx -miny -maxx -maxy
  72. shift 2
  73. case -r
  74. shift 5
  75. case -scroll
  76. shift
  77. case -noscroll
  78. shift
  79. case -hide
  80. shift
  81. }
  82. if(~ $#* 0) cmd = rc
  83. if not cmd = $*
  84. echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
  85. exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
  86. }
  87. }&
  88. }
  89. if not echo new -cd `{pwd} $* >> `{getwctl}