diff options
author | Bart Schaefer <barts@users.sourceforge.net> | 2008-03-03 01:29:17 +0000 |
---|---|---|
committer | Bart Schaefer <barts@users.sourceforge.net> | 2008-03-03 01:29:17 +0000 |
commit | 25848c5aa728935f12cd97ed92412f319048fb87 (patch) | |
tree | 8248a1af2e70f2e5a06794ae7ca9d5eab52bd0ed /Completion/Unix/Type | |
parent | e5a6543e6daeb8cb8e2cd37856814e24ce4407df (diff) | |
download | zsh-25848c5aa728935f12cd97ed92412f319048fb87.tar.gz zsh-25848c5aa728935f12cd97ed92412f319048fb87.tar.xz zsh-25848c5aa728935f12cd97ed92412f319048fb87.zip |
24653, 24659: Completion/Unix/Type/_path_commands: use a helper function
to call "whatis" portably, and use compadd -O to pre-filter matches before reading $_command_descriptions.
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r-- | Completion/Unix/Type/_path_commands | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Completion/Unix/Type/_path_commands b/Completion/Unix/Type/_path_commands index 0a4e3d512..340a013c3 100644 --- a/Completion/Unix/Type/_path_commands +++ b/Completion/Unix/Type/_path_commands @@ -23,6 +23,17 @@ done return 1 } +_call_whatis() { + case "$(whatis --version)" in + (whatis from *) + local -A args + zparseopts -D -A args s: r: + apropos "${args[-r]:-"$@"}" | fgrep "($args[-s]" + ;; + (*) whatis "$@";; + esac +} + _path_commands() { local need_desc expl ret=1 @@ -38,7 +49,7 @@ if zstyle -t ":completion:${curcontext}:" extra-verbose; then if ( [[ -n $first ]] || _cache_invalid command-descriptions ) && \ ! _retrieve_cache command-descriptions; then local line - for line in "${(f)$(_call_program command-descriptions whatis -s 1 -r .\\\*\; whatis -s 6 -r .\\\* 2> /dev/null)}"; do + for line in "${(f)$(_call_program command-descriptions _call_whatis -s 1 -r .\\\*\; _call_whatis -s 6 -r .\\\* 2>/dev/null)}"; do [[ -n ${line:#(#b)([^ ]#) #\([^ ]#\)( #\[[^ ]#\]|)[ -]#(*)} ]] && continue; [[ -z $match[1] || -z $match[3] || -z ${${match[1]}:#*:*} ]] && continue; _command_descriptions[$match[1]]=$match[3] @@ -50,9 +61,10 @@ if zstyle -t ":completion:${curcontext}:" extra-verbose; then fi if [[ -n $need_desc ]]; then - typeset -a dcmds descs cmds + typeset -a dcmds descs cmds matches local desc cmd sep - for cmd in ${(k)commands}; do + compadd "$@" -O matches -k commands + for cmd in $matches; do desc=$_command_descriptions[$cmd] if [[ -z $desc ]]; then cmds+=$cmd |