29 lines
801 B
Plaintext
Raw Normal View History

# bash completion for yp-tools -*- shell-script -*-
2009-06-08 16:45:09 +02:00
_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 | \
cut -d':' -f 1 )' -- "$cur" ) )
2009-10-04 19:42:50 +02:00
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
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh