From 2a7aa9d913dfa2591592bf1b1e0e6a7cf8e63808 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Wed, 21 Mar 2012 11:05:20 +0100 Subject: Revised bash completion Bash completion does not deal properly with profile filenames that contain whitespace. There are some minor tweaks in this commit as well, but those should be harmless. --- contrib/PKGBUILD | 2 +- contrib/bash-completion | 44 ++++++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 27 deletions(-) (limited to 'contrib') diff --git a/contrib/PKGBUILD b/contrib/PKGBUILD index 9fadd7d..12bdec6 100644 --- a/contrib/PKGBUILD +++ b/contrib/PKGBUILD @@ -26,7 +26,7 @@ package() { install -D -m644 LICENSE "$pkgdir/usr/share/licenses/netcfg/LICENSE" # Shell Completion - install -D -m644 contrib/bash-completion "$pkgdir/etc/bash_completion.d/netcfg" + install -D -m644 contrib/bash-completion "$pkgdir/usr/share/bash-completion/completions/netcfg" install -D -m644 contrib/zsh-completion "$pkgdir/usr/share/zsh/site-functions/_netcfg" } diff --git a/contrib/bash-completion b/contrib/bash-completion index d045844..f7273aa 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -1,14 +1,4 @@ -# netcfg completion by Maciej 'macieks' Sitarz - -_connected_prfls () -{ - COMPREPLY=( $( compgen -W "$( ls /run/network/profiles/ )" -- $cur ) ) -} - -_connected_intfs () -{ - COMPREPLY=( $( compgen -W "$( ls /run/network/interfaces/)" -- $cur ) ) -} +# netcfg completion _netcfg () { @@ -21,38 +11,40 @@ _netcfg () 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 /etc/network.d -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' d -printf '%f\n'`" + prfls="$(find -L /etc/network.d/ -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf '%f\n')" - case "${cur}" in - --*) - COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) ) + case "${prev}" in + -R|iface-recon|-D|iface-down) + COMPREPLY=( $( compgen -W "$(ls /run/network/interfaces/)" -- $cur ) ) return 0 ;; - -*) - COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) ) + -r|reconnect|-d|down) + COMPREPLY=( $( compgen -W "$(ls /run/network/profiles/)" -- $cur ) ) return 0 ;; - *) - if [ $COMP_CWORD -eq 1 ]; then - COMPREPLY=( $( compgen -W "${opts} ${lopts} ${cmds} ${prfls}" -- $cur ) ) - fi + -c|check-iface|-u|up) + COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) ) + return 0 ;; esac - case "${prev}" in - -R|iface-recon|-D|iface-down) - _connected_intfs + case "${cur}" in + --*) + COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) ) return 0 ;; - -c|check-iface|-u|up|-r|reconnect|-d|down) - _connected_prfls + -*) + COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) ) return 0 ;; *) + ((COMP_CWORD == 1)) && \ + COMPREPLY=( $( compgen -W "${opts} ${lopts} ${cmds} ${prfls}" -- $cur ) ) ;; esac return 0 } + complete -F _netcfg netcfg complete -F _netcfg netcfg2 -- cgit v1.2.3-24-g4f1b