File: update-service.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 (40 lines) | stat: -rw-r--r-- 1,100 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
# Wed, 13 Mar  2024 16:47:14 +0100
# bash-completion for update-service

_update-service_services()
{
if [ "$(id -u)" != 0 ] && [ "$(id -u)" -ge '1000' ]; then
    username="$(id -u -n)"
    SVDLIST=$(ls --color=no /home/$username/.runit/sv/)
else
    SVDLIST=$(ls --color=no /etc/sv)
    for svd in /usr/share/runit/sv.current/* ; do
      svdbase=${svd##*/}
      [ ! -d /etc/sv/$svdbase ] && SVDLIST="$SVDLIST $svdbase"
    done
fi
echo "$SVDLIST"
}

_update-service_comm()
{
    echo "--add enable --remove disable --list --check "
}

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

complete -F _update-services update-service