]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/delkey
/lib/rob: Just write the code.
[plan9front.git] / rc / bin / delkey
1 #!/bin/rc
2
3 rfork e
4
5 ctl = /mnt/factotum/ctl
6 if(test -r /mnt/term/mnt/factotum/ctl)
7         ctl = /mnt/term/mnt/factotum/ctl
8
9 fn forceit {
10         switch($force){
11         case no
12                 echo -n $* '? [y/n]' > /dev/cons
13                 ok = `{read}
14                 switch($ok){
15                 case y* Y*
16                         echo yes
17                 case q* Q*
18                         exit ''
19                 case *
20                         echo no
21                 }
22         case *
23                 echo yes
24         }
25 }
26
27 fn deleteit {
28         key = `{echo $* | sed 's/ ![0-9a-zA-Z_]+\??/ /g' | sed 's/ +$//'}
29         if(~ `{forceit del$key} yes)
30                 if(! echo del$key > $ctl)
31                         exit bad
32 }
33
34 force = no
35
36 if(~ $1 '-f'){
37         force = yes
38         shift
39 }
40
41 ifs='
42 '
43
44 if(~ $#* 0){
45         for(i in `{cat $ctl})
46                 deleteit $i
47         exit ''
48 }
49
50 for(i in `{grep $"* $ctl})
51         deleteit $i
52 exit ''