File: sv.bash-completion

package info (click to toggle)
runit 2.2.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,568 kB
  • sloc: ansic: 6,071; sh: 3,419; makefile: 399
file content (39 lines) | stat: -rw-r--r-- 1,182 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
# From: Jérémy Lal <kapouer@melix.org>
# To: Debian Bug Tracking System <submit@bugs.debian.org>
# Subject: runit: bash completion for sv
# Date: Thu, 06 Jun 2013 14:00:39 +0200
# 
# Please find attached a bash-completion file for sv.

_sv_services()
{
    if [ "$(id -u)" != 0 ] && [ "$(id -u)" -ge '1000' ]; then
        username="$(id -u -n)"
        /bin/ls --color=no "${SVDIR:-/home/$username/.service/}"
    else
        /bin/ls --color=no "${SVDIR:-/etc/service}"
    fi
}

_sv_commands()
{
    echo "status up down once pause cont hup alarm interrupt quit 1 2 term kill exit start stop reload restart shutdown force-stop force-reload force-restart force-shutdown try-restart check"
}

_sv()
{
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    if [ $COMP_CWORD -eq 1 ]; then
        COMPREPLY=( $( compgen -W "$(_sv_commands)" $cur ) )
    elif [ $COMP_CWORD -ge 2 ]; then
        if [ "$(id -u)" != 0 ] && [ "$(id -u)" -ge '1000' ] ; then
            COMPREPLY=( $( compgen -W "$(_sv_services)" $cur ) )
        else
            COMPREPLY=( $( compgen -W "$(_sv_services)" $cur ) )
            _filedir -d
        fi
    fi
}

complete -F _sv sv