[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 2.0-56-g166ac77
Guillaume Rousse
guillomovitch at gmail.com
Mon Oct 29 23:11:59 UTC 2012
The following commit has been merged in the master branch:
commit e5ac55d5df03b04ff082cebd8245fc28c2ef59fd
Author: Yann Rouillard <yann at opencsw.org>
Date: Tue Oct 30 00:10:27 2012 +0100
new completion: pkgutil
diff --git a/CHANGES b/CHANGES
index 364c93d..83fdd07 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@
* pkg-get: new completion, contributed by Yann Rouillard <yann at opencsw.org>
* pkgadd: new completion, contributed by Yann Rouillard <yann at opencsw.org>
* pkgdrm: new completion, contributed by Yann Rouillard <yann at opencsw.org>
+ * pkgutil: new completion, contributed by Yann Rouillard <yann at opencsw.org>
bash-completion (2.0)
diff --git a/completions/Makefile.am b/completions/Makefile.am
index 3a840c4..5f63e35 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -239,6 +239,7 @@ bashcomp_DATA = a2x \
pkgadd \
pkgrm \
pkgtool \
+ pkgutil \
plague-client \
pm-hibernate \
pm-is-supported \
diff --git a/completions/pkgutil b/completions/pkgutil
new file mode 100755
index 0000000..06bbeaf
--- /dev/null
+++ b/completions/pkgutil
@@ -0,0 +1,96 @@
+# pkgutil completion -*- shell-script -*-
+# Copyright 2006 Yann Rouillard <yann at opencsw.org>
+
+_pkgutil_url2catalog()
+{
+ local filename="$1"
+
+ filename="${filename##*://}"
+ filename="${filename//\//_}"
+ filename="/var/opt/csw/pkgutil/catalog.${filename}_$(uname -p)_$(uname -r)"
+
+ echo "$filename"
+}
+
+_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=()
+
+ i=$cword
+ while [[ $((i--)) -gt 1 ]]; do
+ if [[ "${words[$i]}" = @(-t|--temp) ]]; then
+ local url="${words[$((i+1))]}"
+ local catalog=$(_pkgutil_url2catalog "$url")
+ catalog_files=("$catalog")
+ elif [[ "${words[$i]}" = @(--config) ]]; then
+ configuration_files=( "$(dequote ${words[$((i+1))]})" )
+ elif [[ "${words[$i]}" == @(-i|--install|-u|--upgrade|-r|--remove|-d|--download|-a|--available|-c|--compare|-U|--catalog|-S|--stream) ]]; then
+ command="${words[$i]}"
+ fi
+ done
+
+ if [[ "$prev" = @(-W|--workdir|-P|--pkgdir|-R|--rootpath) ]]; then
+ _filedir -d
+ return 0
+ fi
+
+ if [[ "$prev" = @(-o|--output|--config) ]]; then
+ _filedir
+ return 0
+ 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) )
+ return 0
+ fi
+
+ if [[ "$prev" = @(-T|--target) ]]; then
+ # 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##*:}"}
+ 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 [ $((--i)) -ge 0 ]; do
+ COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
+ done
+ return 0
+ fi
+
+ if [[ -n "$command" ]] && [[ ! "$cur" == -* ]]; then
+
+ local mirrors mirror_url
+ mirrors=$(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" )
+ done
+
+ if [[ "$command" == @(--download|-d|--install|-i|--upgrade|-u|s|--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) )
+
+ elif [[ "$command" == @(-r|--remove) ]]; then
+ local packages_list=$(pkginfo | 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) )
+ fi
+ return 0
+ 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) )
+ return 0
+}
+
+complete -F _pkgutil pkgutil
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/test/completion/pkgutil.exp b/test/completion/pkgutil.exp
new file mode 100644
index 0000000..b4d152e
--- /dev/null
+++ b/test/completion/pkgutil.exp
@@ -0,0 +1 @@
+assert_source_completions pkgutil
diff --git a/test/lib/completions/abook.exp b/test/lib/completions/pkgutil.exp
similarity index 78%
copy from test/lib/completions/abook.exp
copy to test/lib/completions/pkgutil.exp
index 43f6272..e79dea1 100644
--- a/test/lib/completions/abook.exp
+++ b/test/lib/completions/pkgutil.exp
@@ -11,9 +11,7 @@ proc teardown {} {
setup
-assert_complete_any "abook "
-
-
+assert_complete_any "pkgutil "
sync_after_int
--
bash-completion
More information about the Bash-completion-commits
mailing list