2011-11-01 22:14:45 +02:00
|
|
|
# slapt-src completion -*- shell-script -*-
|
2011-10-12 23:01:10 +03:00
|
|
|
|
|
|
|
_slapt_src()
|
|
|
|
{
|
|
|
|
local cur prev words cword
|
|
|
|
_init_completion -n : || return
|
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
--config|-c)
|
|
|
|
_filedir
|
2011-11-20 17:00:03 +03:00
|
|
|
return
|
2011-10-12 23:01:10 +03:00
|
|
|
;;
|
|
|
|
--search|-s|--postprocess|-p)
|
|
|
|
# argument required but no completions available
|
2011-11-20 17:00:03 +03:00
|
|
|
return
|
2011-10-12 23:01:10 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ "$cur" == -* ]]; then
|
2011-11-20 23:42:20 +03:00
|
|
|
COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help )' -- "$cur" ) )
|
2011-10-12 23:01:10 +03:00
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
2011-11-20 17:00:03 +03:00
|
|
|
[[ $COMPREPLY ]] && return
|
2011-10-12 23:01:10 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
local i t
|
|
|
|
# search for last action (-i|-w|-b|-f)
|
|
|
|
for (( i=${#words[@]}-1; i>0; i-- )); do
|
|
|
|
if [[ ${words[i]} == -@(i|w|f|b|-install|-show|-build|-fetch) ]]; then
|
|
|
|
t="all"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2011-11-09 23:28:11 +02:00
|
|
|
if [[ $t != all ]]; then
|
2011-11-20 17:00:03 +03:00
|
|
|
return
|
2011-10-12 23:01:10 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
local config="/etc/slapt-get/slapt-srcrc" # 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
|
2011-11-20 17:00:03 +03:00
|
|
|
if [[ ! -r "$config" ]]; then
|
|
|
|
return
|
2011-10-12 23:01:10 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$cur" == *:* ]]; then
|
|
|
|
local name=${cur%:*}
|
|
|
|
local version=${cur##*:}
|
2011-11-20 23:42:20 +03:00
|
|
|
COMPREPLY=( $( slapt-src --config "$config" --search "^$name" 2> \
|
|
|
|
/dev/null | sed -ne "/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p}" ) )
|
2011-10-12 23:01:10 +03:00
|
|
|
else
|
2011-11-20 23:42:20 +03:00
|
|
|
COMPREPLY=( $( slapt-src --config "$config" --search "^$cur" 2> \
|
|
|
|
/dev/null | sed -ne "/^$cur/{s/ .*$//;p}" ) )
|
2011-10-12 23:01:10 +03:00
|
|
|
fi
|
|
|
|
} && complete -F _slapt_src slapt-src
|
|
|
|
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|