# pkgadd completion -*- shell-script -*- # # Copyright 2006 Yann Rouillard proc _pkgadd { local cur prev words cword _init_completion -n : || return # if a device directory was given # we must complete with the package # available in this directory local device=/var/spool/pkg; local i=$cword { match $(words[$i]) { with -d setglobal 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} == -* ]] { local opts="-a -A -d -k -n -M -P -r -R -s -v -V -x" setglobal COMPREPLY = ''( $(compgen -W "${opts}" -- ${cur}) ) } else { local pkginst_list if [[ -d $device ]] { for filedir in [$[/bin/ls -1 $device]] { if [[ -d "$device/$filedir" ]] && [[ -f "$device/$filedir/pkginfo" ]] { setglobal pkginst_list = ''( ${pkginst_list[@]:-} "$filedir" ) } } setglobal pkginst_list = $(pkginst_list[@]) } else { setglobal 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