# pkgadd completion -*- shell-script -*- # # Copyright 2006 Yann Rouillard proc _pkgadd { var cur = '', prev = '', words = '', cword = '' _init_completion -n : || return # if a device directory was given # we must complete with the package # available in this directory var device = '/var/spool/pkg'; var i = $cword { match $(words[$i]) { with -d set device = $(words[$((i+1))]); break }; }; match $prev { with -d _filedir pkg _filedir -d with -a|-r|-V _filedir with -k|-s|-R _filedir -d with -P|-k|-x with * if [[ ${cur} == -* ]] { var opts = '"-a -A -d -k -n -M -P -r -R -s -v -V -x'" setglobal COMPREPLY = '( '$(compgen -W "${opts}" -- ${cur}) ) } else { var pkginst_list = '' if [[ -d $device ]] { for filedir in [$[/bin/ls -1 $device]] { if [[ -d "$device/$filedir" ]] && [[ -f "$device/$filedir/pkginfo" ]] { set pkginst_list = '( '${pkginst_list[@]:-} "$filedir" ) } } set pkginst_list = $(pkginst_list[@]) } else { set pkginst_list = $[strings $[dequote $device] | \ command grep "^PKG=" | sort -u | cut -d= -f2] } setglobal COMPREPLY = '( '$(compgen -W "$pkginst_list" -- ${cur}) ) } } } && complete -F _pkgadd pkgadd # ex: ts=4 sw=4 et filetype=sh