From 27c11787d7c58b02f12d7afd476ea66abfeecaaf Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 28 Dec 2012 02:43:13 +0100 Subject: Forking netcfg to netctl (2/2) This commit contains the refactoring and rewriting of code. --- contrib/bash-completion | 63 +++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) (limited to 'contrib') diff --git a/contrib/bash-completion b/contrib/bash-completion index dab52ea..b47d92b 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -1,49 +1,30 @@ -# netcfg completion +# netctl completion -_netcfg () +_netctl() { - local cur prev opts lopts cmds prfls + local cur prev prof - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" + 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") - opts="-l -c -u -r -R -d -D -a -v -h" - lopts="--help --version" - cmds="list current check-iface up reconnect iface-recon down iface-down all-down all-suspend" - prfls="$(find -L /etc/network.d/ -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf '%f\n')" - - case "${prev}" in - -R|iface-recon|-D|iface-down) - COMPREPLY=( $( compgen -W "$(ls /run/network/interfaces/)" -- $cur ) ) - return 0 - ;; - -r|reconnect|-d|down) - COMPREPLY=( $( compgen -W "$(ls /run/network/profiles/)" -- $cur ) ) - return 0 - ;; - -c|check-iface|-u|up) - COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) ) - return 0 - ;; - esac - - case "${cur}" in - --*) - COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) ) - return 0 - ;; - -*) - COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) ) - return 0 - ;; - *) - ((COMP_CWORD == 1)) && \ - COMPREPLY=( $( compgen -W "${opts} ${lopts} ${cmds} ${prfls}" -- $cur ) ) + 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) + case $prev in + start|stop|restart|switch-to|status|enable|disable|reenable) + mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$prof" -- $cur) ;; + esac + ;; + *) + COMPREPLY=() + ;; esac +} && +complete -F _netctl netctl - return 0 -} -complete -F _netcfg netcfg +# ex: ts=4 sw=4 et filetype=sh -- cgit v1.2.3-24-g4f1b