blob: 7f5e35b4daf2e67cfceb748d670910194f35094c (
plain)
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
|
## vim:ft=zsh
## wrapper around man, finfo, etc
typeset -a methods
typeset method
typeset -i found check_only all
methods=(man function builtin apt)
while [[ $1 == -* ]] {
case $1 in
-c|--check-only) check_only=1 ;;
-a|--all) all=1 ;;
-|--) shift; break ;;
*) echo "unknown option: $1" ;;
esac
shift
}
function help_check_man { man -w $1 &> /dev/null }
function help_check_function { whichf $1 &> /dev/null }
function help_check_builtin { (( ${+builtins[$1]} )) }
function help_check_apt {
[[ $commands[$1] != ${HOME}* ]] && check_com -c $1 && check_com -c apt-file
}
function help_show_man { man $1 }
function help_show_function { finfo $1 }
function help_show_builtin { man zshbuiltins | less -p " $1" }
function help_show_apt {
apt-cache show ${(s/:/)$(apt-file search -F $commands[$1])[1]}
}
if [[ -z $1 ]] {
echo "Usage: help <command>" > /dev/stderr
return 1
}
for method in $methods; {
if help_check_$method $1; then
((found++))
if ((check_only)) {
echo $method
continue
}
help_show_$method $1
((all)) || break
fi
}
if ((found == 0)) {
echo "Sorry, no clue." > /dev/stderr
return 1
}
|