# pkg-get.completion completion -*- shell-script -*- # # Copyright 2006 Yann Rouillard _have pkg-get && proc _pkg-get_get_catalog_file { local url="$1" local 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 ]] { setglobal conffile = $file break } } setglobal conffile = $(conffile:-/opt/csw/etc/pkg-get.conf) if [[ -z "$url" ]] { setglobal url = $[awk -F= ' $1=="url" { print $2 }' $conffile] } setglobal catalog_file = $(url##*//) setglobal catalog_file = $(catalog_file%%/*) setglobal catalog_file = ""/var/pkg-get/catalog-$catalog_file"" echo $catalog_file } && proc _pkg-get { local cur prev file catalog_file url command setglobal COMPREPLY = ''() setglobal cur = $(COMP_WORDS[COMP_CWORD]) setglobal 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 ]] { setglobal url = $(COMP_WORDS[$((i+1))]) } if [[ "${COMP_WORDS[$i]}" == @(-[aDdiUu]|available|describe|download|install|list|updatecatalog|upgrade) ]] { setglobal command = $(COMP_WORDS[$i]) } } if [[ -n "$command" ]] { if [[ "$command" == @(-[Ddi]|describe|download|install) ]] { setglobal catalog_file = $[_pkg-get_get_catalog_file $url] if [[ -f $catalog_file ]] { local 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} == -* ]] { local opts="-c -d -D -f -i -l -s -S -u -U -v" setglobal COMPREPLY = ''( $(compgen -W "${opts}" -- ${cur}) ) return 0 } else { local 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