summaryrefslogtreecommitdiffstats
path: root/contrib/bash-completion
blob: 5a2dd12f487d368ac470953415bfd6d1fdaac29c (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
# 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 reenable" -- "$cur") )
      ;;
      2)
        [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|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 "start stop" -- "$cur") );;
      2) COMPREPLY=( $(compgen -W "$(_wireless_interfaces)" -- "$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