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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
| | #autoload
(( $+functions[_path_commands_caching_policy] )) ||
_path_commands_caching_policy() {
local file ret=0
local -a oldp dbdirs
# rebuild if cache is more than a week old
oldp=( "$1"(Nmw+1) )
(( $#oldp )) && return 0
dbdirs=( $manpath /usr/share/man /usr/man /var/cache/man /var/catman{,/man} /usr/share/man/(^man*)(N) )
for file in $dbdirs/(windex|whatis|index.(bt|db|dir|pag))(N); do
[[ $file -nt $1 ]] && return 0
ret=1
done
return ret
}
_call_whatis() {
case "$OSTYPE:$(whatis --version)" in
(solaris*)
apropos -s 1 | tr -s $'\t ' ' ' | cut -d ' ' -f 1,3-
;;
(freebsd*) ;&
(*:"whatis from "*)
apropos '.*' | grep "([16]"
;;
(*)
whatis -s 1 -r '.*'
whatis -s 6 -r '.*'
;;
esac
}
_path_commands() {
local need_desc expl ret=1
if zstyle -t ":completion:${curcontext}:commands" extra-verbose; then
local update_policy first
if (( ! $+_cache_command_descriptions )); then
first=yes
typeset -A -g _cache_command_descriptions
fi
zstyle -s ":completion:${curcontext}:commands" cache-policy update_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:commands" \
cache-policy _path_commands_caching_policy
if [[ -n $first ]] && { _cache_invalid command-descriptions ||
! _retrieve_cache command-descriptions }
then
local line
for line in "${(f)$(_call_program command-descriptions _call_whatis)}"; do
[[ -n ${line:#(#b)([^ ]#) #\([^ ]#\)( #\[[^ ]#\]|)[ -]#(*)} ]] && continue;
[[ -z $match[1] || -z $match[3] || -z ${${match[1]}:#*:*} ]] && continue;
_cache_command_descriptions[$match[1]]=$match[3]
done
_store_cache command-descriptions _cache_command_descriptions
fi
(( $+_cache_command_descriptions )) && need_desc=yes
fi
if [[ -n $need_desc ]]; then
typeset -a dcmds descs cmds matches
local desc cmd sep
compadd "$@" -O matches -k commands
for cmd in $matches; do
desc=$_cache_command_descriptions[$cmd]
if [[ -z $desc ]]; then
cmds+=$cmd
else
dcmds+=$cmd
descs+="$cmd:$desc"
fi
done
zstyle -s ":completion:${curcontext}:commands" list-separator sep || sep=--
zformat -a descs " $sep " $descs
descs=("${(@r:COLUMNS-1:)descs}")
_wanted commands expl 'external command' \
compadd "$@" -ld descs -a dcmds && ret=0
_wanted commands expl 'external command' compadd "$@" -a cmds && ret=0
else
_wanted commands expl 'external command' compadd "$@" -k commands && ret=0
fi
# TODO: this is called from '_command_names -e' which is typically used in
# contexts (such as _env) that don't accept directory names. Should this
# 'if' block move up to the "_command_names -" branch of _command_names?
if [[ -o path_dirs ]]; then
local -a path_dirs
path_dirs=(${^path}/*(/N:t))
(( ${#path_dirs} )) &&
_wanted path-dirs expl 'directory in path' compadd "$@" -a path_dirs && ret=0
if [[ $PREFIX$SUFFIX = */* ]]; then
# Find command from path, not hashed
_wanted commands expl 'external command' _path_files -W path -g '*(*)' &&
ret=0
fi
fi
return ret
}
_path_commands "$@"
|