summaryrefslogtreecommitdiffstats
path: root/completions/pkgadd
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--completions/pkgadd41
1 files changed, 20 insertions, 21 deletions
diff --git a/completions/pkgadd b/completions/pkgadd
index 3f5b6a1..bdb9c42 100644
--- a/completions/pkgadd
+++ b/completions/pkgadd
@@ -2,10 +2,10 @@
#
# Copyright 2006 Yann Rouillard <yann@opencsw.org>
-_pkgadd()
+_comp_cmd_pkgadd()
{
- local cur prev words cword
- _init_completion -n : || return
+ local cur prev words cword comp_args
+ _comp_initialize -n : -- "$@" || return
# if a device directory was given
# we must complete with the package
@@ -23,40 +23,39 @@ _pkgadd()
case $prev in
-d)
- _filedir pkg
- _filedir -d
+ _comp_compgen_filedir pkg
;;
-a | -r | -V)
- _filedir
+ _comp_compgen_filedir
;;
-k | -s | -R)
- _filedir -d
+ _comp_compgen_filedir -d
;;
-P | -x) ;;
*)
if [[ ${cur} == -* ]]; then
- local opts="-a -A -d -k -n -M -P -r -R -s -v -V -x"
- COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
+ local -a opts=(-a -A -d -k -n -M -P -r -R -s -v -V -x)
+ _comp_compgen -- -W '"${opts[@]}"'
else
- local pkginst_list
+ local -a pkginst_list
if [[ -d $device ]]; then
- local -a tmplist
- for filedir in $(/bin/ls -1 $device); do
- if [[ -d "$device/$filedir" ]] && [[ -f "$device/$filedir/pkginfo" ]]; then
- tmplist+=(${tmplist[@]:-} "$filedir")
- fi
- done
- pkginst_list="${tmplist[*]}"
+ if _comp_expand_glob pkginst_list '"$device"/*/pkginfo'; then
+ pkginst_list=("${pkginst_list[@]#"$device/"}")
+ pkginst_list=("${pkginst_list[@]%/pkginfo}")
+ fi
else
- pkginst_list="$(strings "$(dequote $device)" |
- command grep ^PKG= | sort -u | cut -d= -f2)"
+ local REPLY
+ _comp_dequote "$device"
+ _comp_split -l pkginst_list "$(strings "${REPLY-}" |
+ command sed -n 's/^PKG=//p' | sort -u)"
fi
- COMPREPLY=($(compgen -W "$pkginst_list" -- ${cur}))
+ ((${#pkginst_list[@]})) &&
+ _comp_compgen -- -W '"${pkginst_list[@]}"'
fi
;;
esac
} &&
- complete -F _pkgadd pkgadd
+ complete -F _comp_cmd_pkgadd pkgadd
# ex: filetype=sh