ui.inc (1156B)
1 wdb=$home/lib/wdb 2 data=$wdb/data 3 index=$wdb/index 4 5 fn main_help{ 6 cat<EOF 7 h - help 8 i - regenerate index 9 s [query] - search 10 t [query] - search by tag 11 T [query] - search by type 12 n - new entry 13 q - quit 14 EOF 15 } 16 17 fn printguid{ 18 id=$1 19 echo $data/$"id 20 grep -n $"id $index/all /dev/null 21 cat $data/$"id 22 echo '---' 23 } 24 25 fn printguids{ 26 test -z $"guids|| 27 for(i in `{seq $#guids}){ 28 echo -n $i^': ' 29 printguid $guids($i) 30 } 31 } 32 33 fn entry{ 34 id=$1 35 echo $data/$id 36 cat $data/$id 37 } 38 39 fn enumer{ 40 echo Found $#* entries. 41 } 42 43 fn main{ 44 echo -n '→ ' 45 input=`{read} 46 cmd=$input(1) 47 arg=$input(2-) 48 switch($"cmd){ 49 case h 50 main_help 51 case i 52 wdb/genindex 53 case s 54 guids=`{wdb/search $"arg < $index/all} 55 enumer $guids 56 printguids 57 case t 58 guids=`{wdb/search -t $"arg < $index/all} 59 enumer $guids 60 printguids 61 case T 62 guids=`{wdb/search -T $"arg < $index/all} 63 enumer $guids 64 printguids 65 case q 66 echo bye 67 exit 68 case p 69 printguids 70 case n 71 guids=`{wdb/new $"arg} 72 if(test -z $status){ 73 echo New entry: $data/$"guids 74 plumb -s 'wdb' $data/$"guids 75 } 76 case * 77 id=$guids($"cmd) 78 if(test -n $"id -a -f $data/^$"id){ 79 entry $"id 80 } 81 if not echo '?' 82 } 83 }