Small yp-tools completion improvements.

Install ypmatch completion only if ypcat is available instead of the
other way around, fix completions when commands are invoked using
paths to them.
This commit is contained in:
Ville Skyttä 2010-01-06 13:27:28 +02:00
parent eb70bc8431
commit 19ca031a08
2 changed files with 9 additions and 7 deletions

View File

@ -27,7 +27,7 @@ bash-completion (2.x)
* Remove many unnecessary short option completions where long ones exist.
* Improve chsh, configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer,
mysqladmin, rsync, screen, service, scp, ssh, sshfs, update-alternatives,
vncviewer, and general hostname completions.
vncviewer, yp-tools, and general hostname completions.
* Add abook and wtf completion, based on work by Raphaël Droz.
* Add cvsps, fusermount, jarsigner, k3b, lftpget, pm-utils, rtcwake, pack200
and unpack200 completions.

View File

@ -1,22 +1,24 @@
# bash completion for yp-tools
have ypmatch &&
have ypcat &&
_ypmatch()
{
local cur map
local cur map cmd
COMPREPLY=()
cur=`_get_cword`
cmd=${1##*/}
[[ $1 == ypcat && $COMP_CWORD -gt 1 ]] && return 0
[[ $1 == ypmatch && $COMP_CWORD -gt 2 ]] && return 0
[[ $cmd == ypcat && $COMP_CWORD -gt 1 ]] && return 0
[[ $cmd == ypmatch && $COMP_CWORD -gt 2 ]] && return 0
if [[ $1 == ypmatch && $COMP_CWORD -eq 1 && ${#COMP_WORDS[@]} -eq 3 ]]; then
if [[ $cmd == ypmatch && $COMP_CWORD -eq 1 && \
${#COMP_WORDS[@]} -eq 3 ]]; then
map=${COMP_WORDS[2]}
COMPREPLY=( $( compgen -W '$( ypcat $map | \
cut -d':' -f 1 )' -- "$cur") )
else
[[ $1 == ypmatch && $COMP_CWORD -ne 2 ]] && return 0
[[ $cmd == ypmatch && $COMP_CWORD -ne 2 ]] && return 0
COMPREPLY=( $( compgen -W \
'$( printf "%s\n" $(ypcat -x | cut -d"\"" -f 2) )' -- "$cur"))
fi