wg-quick: only bash complete existing interfaces for down

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2017-09-06 20:51:41 +02:00
parent 34337b0906
commit 92feabdd17

View file

@ -4,8 +4,8 @@ _wg_quick_completion() {
local i a
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY+=( $(compgen -W "up down" -- "${COMP_WORDS[1]}") )
return
elif [[ $COMP_CWORD -eq 2 ]]; then
if [[ ${COMP_WORDS[1]} == up ]]; then
local old_glob="$(shopt -p nullglob)"
shopt -s nullglob
for i in /etc/wireguard/*.conf; do
@ -18,6 +18,9 @@ _wg_quick_completion() {
COMPREPLY+=( "${a[@]}" )
mapfile -t a < <(compgen -d -- "${COMP_WORDS[2]}")
COMPREPLY+=( "${a[@]}" )
elif [[ ${COMP_WORDS[1]} == down ]]; then
COMPREPLY+=( $(compgen -W "$(wg show interfaces)" -- "${COMP_WORDS[2]}") )
fi
fi
}