Commit 2a7aa9d9 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

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.
parent 3ee71c47
......@@ -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)
......
......@@ -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"
}
# 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
......@@ -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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment