Package: zsh Version: 4.3.2-22 Severity: wishlist Tags: patch Hi!
An inspiration this time from 'fish', a new shell I noticed recently. Though it seem to cater primarily to the newbies, some of the ideas seemed interesting. In particular, was a bit surprised that we never had descriptions for command completion! So, hacked it up.. Here's a new function _path_commands which uses $commands, but also offers descriptions using `whatis`. Uses cache-* and verbose/list-separator styles. I also did a `grep -re '-k commands' *` in the completion dir and changed whatever threw up. May be there are others still remaining... Here's the patch...
diff -Naur Zsh/_command Zsh.new/_command --- Zsh/_command 2006-11-16 17:05:46.655333776 +0530 +++ Zsh.new/_command 2006-11-15 04:08:27.000000000 +0530 @@ -1,10 +1,12 @@ #compdef command +local ret + if [[ CURRENT -ge 3 ]]; then compset -n 2 - _normal + _normal && ret=0 else - local expl - - _wanted commands expl 'external command' compadd "$@" -k commands + _path_commands "$@" && ret=0 fi + +return ret diff -Naur Zsh/_command_names Zsh.new/_command_names --- Zsh/_command_names 2006-11-16 17:05:46.655333776 +0530 +++ Zsh.new/_command_names 2006-11-15 04:09:10.000000000 +0530 @@ -7,7 +7,7 @@ local args defs defs=( - 'commands:external command:compadd -k commands' + 'commands:external command:_path_commands' ) [[ -n "$path[(r).]" || $PREFIX = */* ]] && diff -Naur Zsh/_equal Zsh.new/_equal --- Zsh/_equal 2006-11-16 17:05:46.655333776 +0530 +++ Zsh.new/_equal 2006-11-15 04:43:45.000000000 +0530 @@ -1,5 +1,3 @@ #compdef -equal- -local expl - -_wanted commands expl command compadd -k commands +_path_commands diff -Naur Zsh/_hash Zsh.new/_hash --- Zsh/_hash 2006-11-16 17:05:46.655333776 +0530 +++ Zsh.new/_hash 2006-11-15 04:37:03.000000000 +0530 @@ -33,7 +33,8 @@ elif compset -P 1 '*='; then _wanted -C value values expl 'executable file' _files -g '*(-*)' && ret=0 else - _wanted -C name commands expl command compadd -q -S '=' -k commands && ret=0 + curcontext="${curcontext%:*}:name" + _path_commands -q -S '=' && ret=0 fi fi diff -Naur Zsh/_path_commands Zsh.new/_path_commands --- Zsh/_path_commands 1970-01-01 05:30:00.000000000 +0530 +++ Zsh.new/_path_commands 2006-11-16 02:28:10.000000000 +0530 @@ -0,0 +1,50 @@ +#autoload + +local need_desc expl ret=1 + +if zstyle -T ":completion:${curcontext}:" verbose; then + local update_policy first + if [[ $+_command_descriptions -eq 0 ]]; then + first=yes + typeset -A -g _command_descriptions + fi + zstyle -s ":completion:${curcontext}:" cache-policy update_policy + [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" \ + 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 whatis -s 1 -r .\\\*\; 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] + done + _store_cache command-descriptions _command_descriptions + fi + + (( $#_command_descriptions )) && need_desc=yes +fi + +if [[ -n $need_desc ]]; then + typeset -a dcmds descs cmds + local desc cmd sep + for cmd in ${(@)commands[(I)$PREFIX*]}; do + desc=$_command_descriptions[$cmd] + if [[ -z $desc ]]; then + cmds+=$cmd + else + dcmds+=$cmd + descs+="$cmd:$desc" + fi + done + zstyle -s ":completion:${curcontext}:" 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 + +return $ret diff -Naur Zsh/_path_commands_caching_policy Zsh.new/_path_commands_caching_policy --- Zsh/_path_commands_caching_policy 1970-01-01 05:30:00.000000000 +0530 +++ Zsh.new/_path_commands_caching_policy 2006-11-16 01:42:42.000000000 +0530 @@ -0,0 +1,20 @@ +#autoload + +local oldp file +typeset -a dbfiles + +# rebuild if cache is more than a week old +oldp=( "$1"(Nmw+1) ) +(( $#oldp )) && return 0 + +dbfiles=(/usr/share/man/index.(bt|db|dir|pag)(N) \ + /usr/man/index.(bt|db|dir|pag)(N) \ + /var/cache/man/index.(bt|db|dir|pag)(N) \ + /var/catman/index.(bt|db|dir|pag)(N) \ + /usr/share/man/*/whatis(N)) + +for file in $dbfiles; do + [[ $file -nt $1 ]] && return 0 +done + +return 1 diff -Naur Zsh/_which Zsh.new/_which --- Zsh/_which 2006-11-16 17:05:46.655333776 +0530 +++ Zsh.new/_which 2006-11-15 04:44:26.000000000 +0530 @@ -28,7 +28,7 @@ args=( "$@" ) _alternative -O args \ - 'commands:external command:compadd -k commands' \ + 'commands:external command:_path_commands' \ 'builtins:builtin command:compadd -k builtins' \ 'functions:shell function:compadd -k functions' \ 'aliases:alias:compadd -k aliases' \
Regards, Ramkumar. -- System Information: Debian Release: 4.0 APT prefers testing APT policy: (101, 'testing') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/dash Kernel: Linux 2.6.16-beyond2 Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) Versions of packages zsh depends on: ii debconf [debconf-2.0] 1.5.8 Debian configuration management sy ii libc6 2.3.6.ds1-7 GNU C Library: Shared libraries ii libncurses5 5.5-5 Shared libraries for terminal hand Versions of packages zsh recommends: ii libcap1 1:1.10-14 support for getting/setting POSIX. ii libpcre3 6.7-1 Perl 5 Compatible Regular Expressi -- no debconf information -- One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. -- Robert Firth