File: service

package info (click to toggle)
bash-completion 1%3A1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,508 kB
  • ctags: 24
  • sloc: exp: 5,659; sh: 741; makefile: 203; perl: 59
file content (46 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download
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
# service(8) and /etc/init.d/* completion

# This completes on a list of all available service scripts for the
# 'service' command and/or the SysV init.d directory, followed by
# that script's available commands
#
{ have service || [ -d /etc/init.d/ ]; } &&
_service()
{
    local cur prev sysvdir

    COMPREPLY=()
    _get_comp_words_by_ref cur prev

    # don't complete for things like killall, ssh and mysql if it's
    # the standalone command, rather than the init script
    [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0

    # don't complete past 2nd token
    [ $COMP_CWORD -gt 2 ] && return 0

    [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d

    if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
        _services
    else
        COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
            -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
            $sysvdir/${prev##*/} 2>/dev/null`' -- "$cur" ) )
    fi

    return 0
} &&
complete -F _service service
[ -d /etc/init.d/ ] && (
    services=$(for i in /etc/init.d/*; do
        complete -p ${i##*/} &>/dev/null || printf '%s\n' ${i##*/}; done)
    [ -n "$services" ] && complete -F _service -o default $services;)

# 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