diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-03-21 11:05:20 +0100 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-03-21 11:05:20 +0100 |
commit | 2a7aa9d913dfa2591592bf1b1e0e6a7cf8e63808 (patch) | |
tree | 410ff1f055ff8ab7e7f4b6662f0065c879ee2b81 | |
parent | 3ee71c470423848b8ce4d172047cd9260c5ce9cc (diff) | |
download | netctl-2a7aa9d913dfa2591592bf1b1e0e6a7cf8e63808.tar.gz netctl-2a7aa9d913dfa2591592bf1b1e0e6a7cf8e63808.tar.xz |
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.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | contrib/PKGBUILD | 2 | ||||
-rw-r--r-- | contrib/bash-completion | 44 | ||||
-rw-r--r-- | src/globals | 12 |
4 files changed, 26 insertions, 34 deletions
@@ -73,7 +73,7 @@ netcfg-$(VERSION).tar.xz: | docs pkgbuild: PKGBUILD PKGBUILD: netcfg-$(VERSION).tar.xz - sed -e "s/%pkgver%/$(VERSION)/" -e "s/%md5sum%/$(shell md5sum $< | cut -d ' ' -f 1)/" contrib/PKGBUILD > PKGBUILD + sed -e "s/%pkgver%/$(VERSION)/" -e "s/%md5sum%/$(shell md5sum $< | cut -d ' ' -f 1)/" contrib/PKGBUILD > $@ upload: netcfg-$(VERSION).tar.xz md5sum $< > MD5SUMS.$(VERSION) 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 <macieks@freesco.pl> - -_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 diff --git a/src/globals b/src/globals index d0adb0b..cb5b50a 100644 --- a/src/globals +++ b/src/globals @@ -9,12 +9,12 @@ ### Globals -PROFILE_DIR="/etc/network.d/" -IFACE_DIR="$PROFILE_DIR/interfaces/" -SUBR_DIR="/usr/lib/network/" -HOOKS_DIR="${SUBR_DIR}/hooks/" -CONN_DIR="${SUBR_DIR}/connections/" -STATE_DIR="/run/network/" +PROFILE_DIR="/etc/network.d" +IFACE_DIR="$PROFILE_DIR/interfaces" +SUBR_DIR="/usr/lib/network" +HOOKS_DIR="${SUBR_DIR}/hooks" +CONN_DIR="${SUBR_DIR}/connections" +STATE_DIR="/run/network" |