2011-01-09 04:13:58 +03:00
|
|
|
# bash completion for slackpkg tool
|
2011-04-25 04:57:42 +04:00
|
|
|
# options list is based on `grep '\-.*\=.*)' /usr/sbin/slackpkg | cut -f1 -d\)`
|
2011-01-09 04:13:58 +03:00
|
|
|
|
2011-04-22 02:35:41 +04:00
|
|
|
have slackpkg || return
|
|
|
|
|
2011-01-09 04:13:58 +03:00
|
|
|
_slackpkg()
|
|
|
|
{
|
2011-04-22 03:03:22 +04:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion -n = || return
|
2011-01-09 04:13:58 +03:00
|
|
|
|
2011-04-25 04:57:42 +04:00
|
|
|
local split=false
|
|
|
|
if [[ "$cur" == -?*=* ]]; then
|
|
|
|
prev="${cur%%?(\\)=*}"
|
|
|
|
cur="${cur#*=}"
|
|
|
|
split=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
-delall|-checkmd5|-checkgpg|-checksize|-postinst|-onoff|-download_all|\
|
|
|
|
-dialog|-batch|-only_new_dotnew|-use_includes|-spinning)
|
|
|
|
COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-default_answer)
|
|
|
|
COMPREPLY=( $( compgen -W 'yes no' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-dialog_maxargs|-mirror)
|
|
|
|
# argument required but no completions available
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
$split && return 0
|
|
|
|
|
2011-01-09 04:13:58 +03:00
|
|
|
if [[ "$cur" == -* ]]; then
|
2011-04-25 04:57:42 +04:00
|
|
|
compopt -o nospace
|
|
|
|
COMPREPLY=( $( compgen -W '-delall= -checkmd5= -checkgpg= \
|
|
|
|
-checksize= -postinst= -onoff= -download_all= -dialog= \
|
|
|
|
-dialog_maxargs= -batch= -only_new_dotnew= -use_includes= \
|
|
|
|
-spinning= -default_answer= -mirror=' -- "$cur" ) )
|
2011-01-09 04:13:58 +03:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local confdir="/etc/slackpkg"
|
|
|
|
local config="$confdir/slackpkg.conf"
|
|
|
|
|
|
|
|
if [ ! -r "$config" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
. "$config"
|
|
|
|
|
2011-04-22 03:03:22 +04:00
|
|
|
local action
|
2011-01-28 06:25:50 +03:00
|
|
|
for (( i=1; i<${#words[@]}; i++ )); do
|
|
|
|
if [[ "${words[i]}" != -* ]]; then
|
|
|
|
action="${words[i]}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-04-22 03:03:22 +04:00
|
|
|
case "$action" in
|
2011-01-09 04:13:58 +03:00
|
|
|
generate-template|search|file-search)
|
|
|
|
# argument required but no completions available
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
install-template|remove-template)
|
|
|
|
if [ -e "$confdir/templates" ]; then
|
2011-01-25 03:48:34 +03:00
|
|
|
COMPREPLY=( $( cd "$confdir/templates"; \
|
|
|
|
compgen -f -X "!*.template" -- "$cur" ) )
|
|
|
|
COMPREPLY=( ${COMPREPLY[@]%.template} )
|
2011-01-09 04:13:58 +03:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
2011-01-09 05:00:27 +03:00
|
|
|
remove)
|
2011-01-24 04:01:00 +03:00
|
|
|
_filedir
|
|
|
|
COMPREPLY+=( $( compgen -W 'a ap d e f k kde kdei l n t tcl x \
|
|
|
|
xap y' -- "$cur" ) )
|
2011-01-25 03:48:34 +03:00
|
|
|
COMPREPLY+=( $( cd /var/log/packages; compgen -f -- "$cur" ) )
|
2011-01-24 04:01:00 +03:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
install|reinstall|upgrade|blacklist|download)
|
|
|
|
_filedir
|
|
|
|
COMPREPLY+=( $( compgen -W 'a ap d e f k kde kdei l n t tcl x \
|
|
|
|
xap y' -- "$cur" ) )
|
2011-01-28 06:08:43 +03:00
|
|
|
COMPREPLY+=( $( cut -f 6 -d\ ${WORKDIR}/pkglist 2> /dev/null | \
|
|
|
|
grep "^$cur" ) )
|
2011-01-09 05:00:27 +03:00
|
|
|
return 0
|
|
|
|
;;
|
2011-01-09 04:13:58 +03:00
|
|
|
info)
|
2011-01-28 06:08:43 +03:00
|
|
|
COMPREPLY+=( $( cut -f 6 -d\ ${WORKDIR}/pkglist 2> /dev/null | \
|
|
|
|
grep "^$cur" ) )
|
2011-01-09 04:13:58 +03:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
# we should complete the same as the next `list` + "gpg"
|
|
|
|
COMPREPLY=( $( compgen -W 'gpg' -- "$cur" ) )
|
|
|
|
;&
|
|
|
|
*)
|
|
|
|
COMPREPLY+=( $( compgen -W 'install reinstall upgrade remove \
|
|
|
|
blacklist download update install-new upgrade-all \
|
|
|
|
clean-system new-config check-updates help generate-template \
|
|
|
|
install-template remove-template search file-search info' -- \
|
|
|
|
"$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
} && complete -F _slackpkg slackpkg
|
2011-05-02 13:18:33 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
|
|
|
# sh-basic-offset: 4
|
|
|
|
# sh-indent-comment: t
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|