summaryrefslogtreecommitdiffstats
path: root/contrib/bash-completion
blob: 0e5804f6e3800d1dfb7e83d7d05f3b05d62150e9 (plain)
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
57
58
59
60
61
62
# netctl completion


_wireless_interfaces()
{
    local iface

    for iface in /sys/class/net/*/wireless/; do
        echo ${iface:15:-10}
    done
}


_netctl_profiles()
{
    find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name '*.conf' -not -name '*.service' -printf "%f\n"
}


_netctl()
{
    local cur=${COMP_WORDS[COMP_CWORD]}

    case $COMP_CWORD in
      1)
        COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable is-enabled reenable" -- "$cur") )
      ;;
      2)
        [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|is-enabled|reenable) ]] &&
          mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur")
      ;;
    esac
} &&
complete -F _netctl netctl


_netctl_auto()
{
    local cur=${COMP_WORDS[COMP_CWORD]}

    case $COMP_CWORD in
      1)
        COMPREPLY=( $(compgen -W "--help --version list current switch-to enable disable enable-all disable-all" -- "$cur") )
      ;;
      2)
        [[ ${COMP_WORDS[COMP_CWORD-1]} = @(switch-to|enable|disable) ]] &&
          mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur")
      ;;
    esac
} &&
complete -F _netctl_auto netctl-auto


_wifi_menu()
{
    (( COMP_CWORD == 1 )) &&
      COMPREPLY=( $(compgen -W "$(_wireless_interfaces)" -- "${COMP_WORDS[1]}") )
} &&
complete -F _wifi_menu wifi-menu


# ex: ts=4 sw=4 et filetype=sh