# pkg-get.completion completion -*- shell-script -*- # # Copyright 2006 Yann Rouillard _have pkg-get && proc _pkg-get_get_catalog_file { var url = $1 var catalog_file = '', i = '', conffile = '' for file in [/etc/opt/csw/pkg-get.conf /opt/csw/etc/pkg-get.conf /etc/pkg-get.conf] { if [[ -f $file ]] { set conffile = $file break } } set conffile = $(conffile:-/opt/csw/etc/pkg-get.conf) if [[ -z "$url" ]] { set url = $[awk -F= ' $1=="url" { print $2 }' $conffile] } set catalog_file = $(url##*//) set catalog_file = $(catalog_file%%/*) set catalog_file = ""/var/pkg-get/catalog-$catalog_file"" echo $catalog_file } && proc _pkg-get { var cur = '', prev = '', file = '', catalog_file = '', url = '', command = '' setglobal COMPREPLY = ''() set cur = $(COMP_WORDS[COMP_CWORD]) set prev = $(COMP_WORDS[COMP_CWORD-1]) if [[ "${prev}" == "-s" ]] { return 1 } setglobal i = $(#COMP_WORDS[*]) { setglobal i = $shExpr('i-1') if [[ "${COMP_WORDS[$i]}" == -s ]] { set url = $(COMP_WORDS[$((i+1))]) } if [[ "${COMP_WORDS[$i]}" == @(-[aDdiUu]|available|describe|download|install|list|updatecatalog|upgrade) ]] { set command = $(COMP_WORDS[$i]) } } if [[ -n "$command" ]] { if [[ "$command" == @(-[Ddi]|describe|download|install) ]] { set catalog_file = $[_pkg-get_get_catalog_file $url] if [[ -f $catalog_file ]] { var packages_list = $[awk ' $0 ~ /BEGIN PGP SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' $catalog_file] setglobal COMPREPLY = '( '$(compgen -W "${packages_list}" -- ${cur}) ) } } return 0 } if [[ ${cur} == -* ]] { var opts = '"-c -d -D -f -i -l -s -S -u -U -v'" setglobal COMPREPLY = '( '$(compgen -W "${opts}" -- ${cur}) ) return 0 } else { var commands = '"available describe download install list \ updatecatalog upgrade'" setglobal COMPREPLY = '( '$(compgen -W "${commands}" -- ${cur}) ) return 0 } } && complete -F _pkg-get pkg-get # ex: ts=4 sw=4 et filetype=sh