plan9fox/rc/bin/lookman
Ori Bernstein 5bc9b0c3ca improve usage messages (thanks henesy)
Fix inconsistencies between programs and their usage
messages,  correct instances where information seems
to be missing or lost. This  includes missing arguments,
making usage consistent with manuals, and so on.
2020-03-10 10:09:34 -07:00

37 lines
730 B
Bash
Executable file

#!/bin/rc
# Usage: lookman key ...
# prints out the names of all manual pages containing all the given keywords
rfork e
index=/sys/lib/man/lookman/index
t1=/tmp/look1.$pid
t2=/tmp/look2.$pid
fn sigexit {
rm -f $t1 $t2
exit
}
fn sigint sighup sigterm {
rm -f $t1 $t2
exit note
}
*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_. \012'} # fold case, delete funny chars
if(~ $#* 0){
echo usage: lookman key ... >/fd/2
exit usage
}
look $1 $index | sed 's/.* //' | sort -u >$t1
shift
for(i in $*){
look $i $index | sed 's/.* //' | sort -u |
awk 'BEGIN {
while (getline < "'$t1'" > 0)
table[$0] = 1
}
{ if (table[$0]) print }
' > $t2
mv $t2 $t1
}
sort $t1 | sed 's;/sys/man/;;
s;(.*)/(.*);man \1 \2 # \2(\1);'
exit ''