1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#-*-sh-*-
if _have checkrestart; then
_checkrestart(){
# shellcheck disable=2034
local cur prev words cword
# -s as --exclude=ARG -> exclude= arg
# -n: means do not break words at :
_init_completion -s -n: || return
#_expand # replace ~
case "$prev" in
-b|--blocklistfile) _filedir ;;
-x|--exclude)
if [[ $cur = *:* ]]; then
# -x file:/roo<TAB>
prev=${cur%%?(\\):*}
cur=${cur#*:}
case "$prev" in
package) COMPREPLY=($(apt-cache --no-generate pkgnames "$cur" 2>/dev/null)) ;;
unit|suggested-unit|dangerous-unit)
# based on _services from bash-completion
COMPREPLY=($(compgen -W "$(systemctl list-units --full --all 2>/dev/null | awk '$1~/\.service$/{print $1}')" -- "$cur"))
_filedir
;;
suggested-initscript|dangerous-initscript)
COMPREPLY=($(compgen -W "$(command find /etc/init.d)" -- "$cur"))
;;
program) _pnames && _filedir ;;
pid) _pids ;;
file) _filedir ;;
esac
else
# -x f<TAB>
compopt -o nospace
COMPREPLY=($(compgen -W "package: unit: program: pid: file: unit: suggested-unit: dangerous-unit: suggested-initscript: dangerous-initscript: " -- "$cur"))
fi
;;
--exclude-package)
COMPREPLY=($(apt-cache --no-generate pkgnames "$cur" 2>/dev/null))
;;
--exclude-unit|--dont-suggest-unit|--dangerous-unit)
COMPREPLY=($(compgen -W "$(systemctl list-units --full --all 2>/dev/null | awk '$1~/\.service$/{print $1}')" -- "$cur"))
_filedir
;;
--exclude-program) _pnames && _filedir;;
--exclude-pid) _pids ;;
--exclude-file) _filedir ;;
--dont-suggest-initscript|--dangerous-initscript)
COMPREPLY=($(compgen -W "$(command find /etc/init.d)" -- "$cur"));;
*)
if [[ "$cur" == -* ]] || [ "$cword" = 1 ]; then
# --hel<TAB> or 'checkrestart <TAB>
COMPREPLY=($(compgen -W "$(_parse_help "$1")" -- "$cur"))
else
_filedir
fi
;;
esac
}
complete -F _checkrestart checkrestart
fi
|