# pkgutil completion -*- shell-script -*- # Copyright 2006 Yann Rouillard proc _pkgutil_url2catalog { local filename="$1" setglobal filename = $(filename##*://) setglobal filename = $(filename//\//_) setglobal filename = ""/var/opt/csw/pkgutil/catalog.$(filename)_$[uname -p]_$[uname -r]"" echo $filename } proc _pkgutil { local cur prev words cword _init_completion -n : || return local command catalog_files configuration_files declare -a configuration_files=("/opt/csw/etc/pkgutil.conf" "/etc/opt/csw/pkgutil.conf") declare -a catalog_files=() setglobal i = $cword { if [[ "${words[$i]}" == -@(t|-temp) ]] { local url="$(words[$((i+1))])" local catalog=$[_pkgutil_url2catalog $url] setglobal catalog_files = ''("$catalog") } elif [[ "${words[$i]}" == --config ]] { setglobal configuration_files = ''( "$(dequote ${words[$((i+1))]})" ) } elif [[ "${words[$i]}" == -@([iurdacUS]|-install|-upgrade|-remove|-download|-available|-compare|-catalog|-stream) ]] { setglobal command = $(words[$i]) } } if [[ "$prev" == -@([WPR]|-workdir|-pkgdir|-rootpath) ]] { _filedir -d return 0 } if [[ "$prev" == -@(o|-output|-config) ]] { _filedir return 0 } if [[ "$prev" == -@(p|-param) ]] { compopt -o nospace setglobal COMPREPLY = ''( $(compgen -W "mirror: pkgaddopts: pkgrmopts: wgetopts: use_gpg: use_md5: pkgliststyle: maxpkglist: noncsw: stop_on_hook_soft_error: exclude_pattern: gpg_homedir: root_path: deptree_filter_common: show_current: catalog_not_cached: catalog_update:" -- $cur) ) return 0 } if [[ "$prev" == @(-T|--target) ]] { # Work-around bash_completion issue where bash interprets a colon # as a separator, borrowed from maven completion code which borrowed # it from darcs completion code :) local colonprefixes=$(cur%"${cur##*:}") setglobal COMPREPLY = ''( $(compgen -W "sparc:5.9 sparc:5.10 sparc:5.11 i386:5.9 i386:5.10 i386:5.11" -- $cur) ) local i=$(#COMPREPLY[*]) while test $shExpr('--i') -ge 0 { compat array-assign COMPREPLY '$i' $(COMPREPLY[$i]#"$colonprefixes") } return 0 } if [[ -n "$command" ]] && [[ ! "$cur" == -* ]] { local mirrors mirror_url setglobal mirrors = $[awk -F= ' $1 ~ /^ *mirror *$/ { print $2 }' $(configuration_files[@])] setglobal mirrors = $(mirrors:-http://mirror.opencsw.org/opencsw/testing) for mirror_url in [$mirrors] { local catalog=$[_pkgutil_url2catalog $mirror_url] setglobal catalog_files = ''( "${catalog_files[@]}" "$catalog" ) } if [[ "$command" == -@([dius]|-download|-install|-upgrade|-stream) ]] { local packages_list=$[awk ' $0 ~ /BEGIN PGP SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' $(catalog_files[@])] setglobal COMPREPLY = ''( $(compgen -W "${packages_list}" -- $cur) ) } elif [[ "$command" == @(-r|--remove) ]] { local packages_list=$[pkginfo | awk ' $2 ~ /^CSW/ { printf ("%s|",$2) }] setglobal packages_list = $(packages_list%|) setglobal packages_list = $[nawk " \$3 ~ /^$packages_list\$/ { print \$1 }" $(catalog_files[@])] setglobal COMPREPLY = ''( $(compgen -W "${packages_list}" -- $cur) ) } return 0 } local commands="-i --install -u --upgrade -r --remove -d --download -U --catalog -a --available --describe -c --compare -C --compare-diff -A --compare-avail -e --email -t --temp -x --exclude -W --workdir -P --pkgdir -R --rootpath --config -y --yes -f --force -n --nomod -N --nodeps -D --debug --trace -h --help -v --version -V --syscheck -l --list -L --listfile -F --findfile --deptree --extract -s --stream -o --output -T --target --single -p --param --parse --cleanup --catinfo" setglobal COMPREPLY = ''( $(compgen -W "${commands}" -- $cur) ) return 0 } complete -F _pkgutil pkgutil # ex: ts=4 sw=4 et filetype=sh