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