1 # invoke-rc.d(8) completion                                -*- shell-script -*-
2 #
3 # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
4 
_invoke_rc_d()5 _invoke_rc_d()
6 {
7     local cur prev words cword
8     _init_completion || return
9 
10     local sysvdir services options valid_options
11 
12     [[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d ||
13         sysvdir=/etc/init.d
14 
15     services=($(printf '%s ' $sysvdir/!(README*|*.sh|$_backup_glob)))
16     services=(${services[@]#$sysvdir/})
17     options=(--help --quiet --force --try-anyway --disclose-deny --query
18         --no-fallback)
19 
20     if [[ $cword -eq 1 || $prev == --* ]]; then
21         valid_options=($(
22             tr " " "\n" <<<"${words[*]} ${options[*]}" |
23                 command sed -ne "/$(command sed 's/ /\\|/g' <<<"${options[*]}")/p" |
24                 sort | uniq -u
25         ))
26         COMPREPLY=($(compgen -W '${valid_options[@]} ${services[@]}' -- "$cur"))
27     elif [[ -x $sysvdir/$prev ]]; then
28         COMPREPLY=($(compgen -W '`command sed -e "y/|/ /" \
29             -ne "s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
30             $sysvdir/$prev`' -- "$cur"))
31     else
32         COMPREPLY=()
33     fi
34 
35 } &&
36     complete -F _invoke_rc_d invoke-rc.d
37 
38 # ex: filetype=sh
39