diff options
Diffstat (limited to 'contrib/bash-completion')
-rw-r--r-- | contrib/bash-completion | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/contrib/bash-completion b/contrib/bash-completion index 49f1e6b..4ffcabd 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -1,30 +1,57 @@ # netctl completion -_netctl() + +_wireless_interfaces() +{ + local iface + + for iface in /sys/class/net/*/wireless/; do + echo ${iface:15:-10} + done +} + + +_netctl_profiles() { - local cur prev prof + find -L /etc/network.d -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name '*.conf' -not -name '*.service' -printf "%f\n" +} - cur=${COMP_WORDS[COMP_CWORD]} - prev=${COMP_WORDS[COMP_CWORD-1]} - prof=$(find -L /etc/network.d -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) ) + COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable reenable" -- "$cur") ) ;; 2) - case $prev in - start|stop|restart|switch-to|status|enable|disable|reenable) - mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$prof" -- $cur) - ;; - esac - ;; - *) - COMPREPLY=() + [[ ${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 |