35 lines
865 B
Plaintext
Raw Normal View History

2009-06-08 16:45:09 +02:00
# bash completion for yp-tools
_ypmatch()
{
local cur prev words cword
_init_completion || return
2009-06-08 16:45:09 +02:00
local map cmd=${1##*/}
2009-06-08 16:45:09 +02:00
[[ $cmd == ypcat && $cword -gt 1 ]] && return 0
[[ $cmd == ypmatch && $cword -gt 2 ]] && return 0
2009-06-08 16:45:09 +02:00
if [[ $cmd == ypmatch && $cword -eq 1 && ${#words[@]} -eq 3 ]]; then
map=${words[2]}
COMPREPLY=( $( compgen -W '$( ypcat $map 2>/dev/null | \
2009-10-04 19:42:50 +02:00
cut -d':' -f 1 )' -- "$cur") )
else
[[ $cmd == ypmatch && $cword -ne 2 ]] && return 0
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( compgen -W \
'$( printf "%s\n" $(ypcat -x 2>/dev/null | \
cut -d"\"" -f 2) )' -- "$cur") )
2009-10-04 19:42:50 +02:00
fi
2009-06-08 16:45:09 +02:00
2009-10-04 19:42:50 +02:00
return 0
2009-06-08 16:45:09 +02:00
} &&
complete -F _ypmatch ypmatch ypcat
# Local variables:
# mode: shell-script
2009-10-04 19:42:50 +02:00
# sh-basic-offset: 4
# sh-indent-comment: t
2009-10-04 19:42:50 +02:00
# indent-tabs-mode: nil
# End:
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh