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
|
# rc-service(8) completion -*- shell-script -*-
#
# Adapted from update-rc.d
#
# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
# 2018 Mathieu Roy <yeupou@gnu.org>
# 2018 Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
_rc_service()
{
local cur prev words cword
_init_completion || return
local sysvdir services options valid_options
sysvdir=/etc/init.d
services=( $( printf '%s ' $sysvdir/!(README*|*.sh|$_backup_glob) ) )
services=( ${services[@]#$sysvdir/} )
options=( -d --debug \
-D --nodeps \
-e --exists \
-c --ifcrashed \
-i --ifexists \
-I --ifinactive \
-N --ifnotstarted \
-s --ifstarted \
-S --ifstopped \
-l --list \
-r --resolve \
-Z --dry-run \
-h --help \
-C --nocolor \
-V --version \
-v --verbose \
-q --quiet \
)
if [[ ($cword -eq 1) || ("$prev" == -* ) ]]; then
COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
-- "$cur" ) )
elif [[ -x $sysvdir/$prev ]]; then
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
-ne "s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
$sysvdir/$prev`' \
-- "$cur" ) )
else
COMPREPLY=()
fi
return 0
} &&
complete -F _rc_service rc-service
# ex: filetype=sh
|