-
Notifications
You must be signed in to change notification settings - Fork 0
/
manhunt
executable file
·66 lines (50 loc) · 1.13 KB
/
manhunt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
program=""
keyword=""
context=10
search_help=false
usage (){
echo ${0##*/}
echo "${0##*/}: Searches manpage for keyword"
echo "Usage: ${0##*/} [-h] [-c X] program keyword"
echo -e "Options
\t-h\tSearch help options rather than manpage
\t-c X\t Provide X lines of context"
exit 1
}
#oneshot for printing one entire screen of '='
repl() { printf "$1"'%.s' $(eval "echo {1.."$(($2))"}"); }
while getopts "hc:" opt; do
case $opt in
c )
context=$OPTARG
;;
h )
search_help=true
;;
? )
usage
;;
: )
echo "Option requires argument: $opt"
usage
;;
esac
done
shift $((OPTIND-1))
#save separator string
separator="$(repl = $(tput cols))"
#Searches manpage with context
if [ "$#" -lt 2 ]; then
usage
fi
program="$1"
keyword="$2"
keyword=${keyword/'-'/'\-'}
helptext=
if [ "$search_help" = true ]; then
helptext=$($program --help)
else
helptext=$(man $program)
fi
ggrep --color=auto --group-separator $separator -B $context -A $context "$keyword" <<< "$helptext"