slapt-get: Respect settings supplied by --config option.

Also complete only available packages as argument to --install option.
This commit is contained in:
Igor Murzov 2011-06-12 18:03:08 +04:00
parent 4e79c13d0d
commit 1f50618715

View File

@ -32,9 +32,12 @@ _slapt_get()
local i t
# search for last action (--install|--install-set|--remove|--show|--filelist)
for (( i=${#words[@]}-1; i>0; i-- )); do
if [[ ${words[i]} == -@(i|-install|-show) ]]; then
if [[ ${words[i]} == --show ]]; then
t="all"
break
elif [[ ${words[i]} == -@(i|-install) ]]; then
t="avl"
break
elif [[ ${words[i]} == --install-set ]]; then
t="set"
break
@ -44,15 +47,32 @@ _slapt_get()
fi
done
local config="/etc/slapt-get/slapt-getrc" # default config location
# search for config
for (( i=${#words[@]}-1; i>0; i-- )); do
if [[ ${words[i]} == -@(c|-config) ]]; then
config="${words[i+1]}"
break
fi
done
if [ ! -r "$config" ]; then
return
fi
case $t in
all) # --install|-i|--show
all) # --show
# slapt-get will fail to search for "^name-version"
# it can search for names only
local name=$( echo $cur | cut -f1 -d- )
COMPREPLY=( $( slapt-get --search "^$name" 2> /dev/null | \
local name=${cur%%-*}
COMPREPLY=( $( slapt-get -c $config --search "^$name" 2>/dev/null |\
sed -ne "/^$cur/{s/ .*$//;p}" ) )
return 0
;;
avl) # --install|-i|
COMPREPLY=( $( slapt-get -c $config --available 2>/dev/null | \
sed -ne "/^$cur/{s/ .*$//;p}") )
return 0
;;
ins) # --remove|--filelist
COMPREPLY=( $( cd /var/log/packages; compgen -f -- "$cur" ) )
return 0