diff options
-rw-r--r-- | contrib/PKGBUILD | 1 | ||||
-rw-r--r-- | contrib/bash-completion | 55 | ||||
-rw-r--r-- | contrib/zsh-completion | 64 |
3 files changed, 106 insertions, 14 deletions
diff --git a/contrib/PKGBUILD b/contrib/PKGBUILD index e743bfe..d614dfd 100644 --- a/contrib/PKGBUILD +++ b/contrib/PKGBUILD @@ -28,5 +28,6 @@ package() { # Shell Completion install -D -m644 contrib/bash-completion "$pkgdir/usr/share/bash-completion/completions/netctl" + install -D -m644 contrib/zsh-completion "$pkgdir/usr/share/zsh/site-functions/_netctl" } 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 diff --git a/contrib/zsh-completion b/contrib/zsh-completion new file mode 100644 index 0000000..77bf1f9 --- /dev/null +++ b/contrib/zsh-completion @@ -0,0 +1,64 @@ +#compdef netctl netctl-auto wifi-menu + + +(( $+function[_wireless_interfaces] )) || +_wireless_interfaces() { + local interfaces + interfaces=(/sys/class/net/*/wireless(/)) + print -l ${${(R)interfaces%/wireless}:t} +} + + +(( $+function[_netctl_command] )) || +_netctl_command() { + [[ $words[1] = (start|stop|restart|switch-to|status|enable|disable|reenable) ]] && + compadd "${(f)$(find -L /etc/network.d -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name '*.conf' -not -name '*.service' -printf "%f\n")}" +} + + +_netctl_commands() { + local -a _commands + _commands=( + 'list:List available profiles' + 'store:Save which profiles are active' + 'restore:Load saved profiles' + 'stop-all:Stops all profiles' + 'start:Start a profile' + 'stop:Stop a profile' + 'restart:Restart a profile' + 'switch-to:Switch to a profile' + 'status:Show runtime status of a profile' + 'enable:Enable the systemd unit for a profile' + 'disable:Disable the systemd unit for a profile' + 'reenable:Reenable the systemd unit for a profile' + ) + _describe "netctl commands" _commands +} + + +case $service in + netctl) + case $CURRENT in + 2) + _arguments \ + '(- :)--version[display version information]' \ + '(- :)--help[display help message]' \ + '(-)::netctl commands:_netctl_commands' + ;; + 3) + shift words + [[ $words[1] != -* ]] && + curcontext="${curcontext%:*}-${words[1]}:" _netctl_command + ;; + esac + ;; + netctl-auto) + case $CURRENT in + 2) compadd start stop;; + 3) compadd "${(f)$(_wireless_interfaces)}";; + esac + ;; + wifi-menu) + (( CURRENT == 2 )) && compadd "${(f)$(_wireless_interfaces)}" + ;; +esac |