diff options
Diffstat (limited to 'completions/pkgutil')
-rw-r--r-- | completions/pkgutil | 72 |
1 files changed, 44 insertions, 28 deletions
diff --git a/completions/pkgutil b/completions/pkgutil index 91d8748..63dc400 100644 --- a/completions/pkgutil +++ b/completions/pkgutil @@ -1,7 +1,7 @@ -# pkgutil completion -*- shell-script -*- +# pkgutil completion -*- shell-script -*- # Copyright 2006 Yann Rouillard <yann@opencsw.org> -_pkgutil_url2catalog() +_comp_cmd_pkgutil__url2catalog() { local filename="$1" @@ -9,44 +9,50 @@ _pkgutil_url2catalog() filename="${filename//\//_}" filename="/var/opt/csw/pkgutil/catalog.${filename}_$(uname -p)_$(uname -r)" - echo "$filename" + REPLY=$filename } -_pkgutil() +_comp_cmd_pkgutil() { - local cur prev words cword - _init_completion -n : || return + local cur prev words cword comp_args + _comp_initialize -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=() + local command="" catalog_files configuration_files + local -a configuration_files=( + "/opt/csw/etc/pkgutil.conf" "/etc/opt/csw/pkgutil.conf") + local -a catalog_files=() - local i=$cword + local i=$cword REPLY while ((i-- > 1)); do if [[ ${words[i]} == -@(t|-temp) ]]; then local url="${words[i + 1]}" - local catalog=$(_pkgutil_url2catalog "$url") - catalog_files=("$catalog") + _comp_cmd_pkgutil__url2catalog "$url" + catalog_files=("$REPLY") elif [[ ${words[i]} == --config ]]; then - configuration_files=("$(dequote ${words[i + 1]})") + local REPLY + _comp_dequote "${words[i + 1]}" + [[ ${REPLY-} ]] && configuration_files=("$REPLY") elif [[ ${words[i]} == -@([iurdacUS]|-install|-upgrade|-remove|-download|-available|-compare|-catalog|-stream) ]]; then command="${words[i]}" fi done if [[ $prev == -@([WPR]|-workdir|-pkgdir|-rootpath) ]]; then - _filedir -d + _comp_compgen_filedir -d return fi if [[ $prev == -@(o|-output|-config) ]]; then - _filedir + _comp_compgen_filedir return fi if [[ $prev == -@(p|-param) ]]; then compopt -o nospace - 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)) + _comp_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:' return fi @@ -55,7 +61,8 @@ _pkgutil() # as a separator, borrowed from maven completion code which borrowed # it from darcs completion code :) local colonprefixes=${cur%"${cur##*:}"} - COMPREPLY=($(compgen -W "sparc:5.9 sparc:5.10 sparc:5.11 i386:5.9 i386:5.10 i386:5.11" -- $cur)) + _comp_compgen -- -W 'sparc:5.9 sparc:5.10 sparc:5.11 i386:5.9 i386:5.10 + i386:5.11' local i=${#COMPREPLY[*]} while ((i-- > 0)); do COMPREPLY[i]=${COMPREPLY[i]#"$colonprefixes"} @@ -63,33 +70,42 @@ _pkgutil() return fi - if [[ -v command && $cur != -* ]]; then + if [[ $command && $cur != -* ]]; then local mirrors mirror_url - mirrors=$(awk -F= ' $1 ~ /^ *mirror *$/ { print $2 }' "${configuration_files[@]}") + mirrors=$(_comp_awk -F = ' $1 ~ /^ *mirror *$/ { print $2 }' "${configuration_files[@]}") mirrors=${mirrors:-http://mirror.opencsw.org/opencsw/testing} for mirror_url in $mirrors; do - local catalog=$(_pkgutil_url2catalog "$mirror_url") - catalog_files=("${catalog_files[@]}" "$catalog") + _comp_cmd_pkgutil__url2catalog "$mirror_url" + catalog_files+=("$REPLY") done if [[ $command == -@([dius]|-download|-install|-upgrade|-stream) ]]; then - local packages_list=$(awk ' $0 ~ /BEGIN PGP SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' "${catalog_files[@]}") - COMPREPLY=($(compgen -W "${packages_list}" -- $cur)) + local packages_list=$(_comp_awk ' $0 ~ /BEGIN PGP SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' "${catalog_files[@]}") + _comp_compgen -- -W "${packages_list}" elif [[ $command == @(-r|--remove) ]]; then - local packages_list=$(pkginfo | awk ' $2 ~ /^CSW/ { printf ("%s|",$2) }') + local packages_list=$( + pkginfo | _comp_awk ' $2 ~ /^CSW/ { printf ("%s|",$2) }' + ) packages_list=${packages_list%|} packages_list=$(nawk " \$3 ~ /^$packages_list\$/ { print \$1 }" "${catalog_files[@]}") - COMPREPLY=($(compgen -W "${packages_list}" -- $cur)) + _comp_compgen -- -W "${packages_list}" fi return fi - 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" - COMPREPLY=($(compgen -W "${commands}" -- $cur)) + local -a commands=( + --install --upgrade --remove --download --catalog --available + --describe --compare --compare-diff --compare-avail --email --temp + --exclude --workdir --pkgdir --rootpath --config --yes --force --nomod + --nodeps --debug --trace --help --version --syscheck --list --listfile + --findfile --deptree --extract --stream --output --target --single + --param --parse --cleanup --catinfo + ) + _comp_compgen -- -W '"${commands[@]}"' } && - complete -F _pkgutil pkgutil + complete -F _comp_cmd_pkgutil pkgutil # ex: filetype=sh |