File: run-help

package info (click to toggle)
zsh-beta 4.1.0-dev-4-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,064 kB
  • ctags: 6,159
  • sloc: ansic: 73,617; sh: 4,600; makefile: 630; perl: 623; awk: 293; sed: 16
file content (85 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (3)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /usr/bin/zsh
#
# Figure out where to get the best help, and get it.
#
# This version adapted for Debian GNU/Linux by Robert Leslie <rob@mars.org>
# from source written by Bart Schaefer <schaefer@brasslantern.com>,
# and modified by Clint Adams <schizo@debian.org>.
#

emulate -R zsh
setopt localoptions

: ${HELPDIR:=/usr/share/zsh/help}

[[ $1 == "." ]] && 1="dot"
[[ $1 == ":" ]] && 1="colon"

if [[ $# == 0 || $1 == "-l" ]]
then
    if [[ -n "${HELPDIR:-}" && -d $HELPDIR ]]
    then
	echo "Here is a list of topics for which special help is available:"
	echo ""
	print -rc $HELPDIR/*(:t)
    else
	echo "There is no list of special help topics available at this time."
    fi
    return 0
elif [[ -n "${HELPDIR:-}" && -r $HELPDIR/$1 && $1 != compctl ]]
then
    ${=PAGER:-/usr/bin/pager} $HELPDIR/$1
    return $?
fi

# No zsh help; use "whence" to figure out where else we might look
local what places newline='
'
integer i=0 didman=0

places=( "${(@f)$(builtin whence -va $1)}" )

while ((i++ < $#places))
do
    what=$places[$i]
    builtin print -r $what
    case $what in
    (*( is an alias)*)
	[[ ${what[(w)6]:t} != ${what[(w)1]} ]] && run-help ${what[(w)6]:t}
	;;
    (*( is a * function))
	case ${what[(w)1]} in
	(comp*) man zshcompsys;;
	(zf*) man zshftpsys;;
	(*) builtin functions ${what[(w)1]} | ${=PAGER:-/usr/bin/pager};;
	esac;;
    (*( is a * builtin))
	case ${what[(w)1]} in
	(compctl) man zshcompctl;;
	(comp*) man zshcompwid;;
	(bindkey|vared|zle) man zshzle;;
	(*setopt) man zshoptions;;
	(cap|getcap|setcap) ;&
	(clone) ;&
	(ln|mkdir|mv|rm|rmdir|sync) ;&
	(sched) ;&
	(stat) man zshmodules;;
	(zftp) man zshftpsys;;
	(*) man zshbuiltins;;
	esac
	;;
    (*( is hashed to *))
	man ${what[(w)-1]:t}
	;;
    (*)
	((! didman++)) && man $1
	;;
    esac
    if ((i < $#places && ! didman))
    then
	builtin print -nP "%SPress any key for more help or q to quit%s"
	builtin read -k what
	[[ $what != $newline ]] && echo
	[[ $what == [qQ] ]] && break
    fi
done