2017-11-30 15:23:50 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2018-01-03 20:58:00 +00:00
|
|
|
# Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2017-01-02 04:33:43 +00:00
|
|
|
|
|
|
|
_wg_quick_completion() {
|
2017-02-23 03:39:06 +00:00
|
|
|
local i a
|
2017-01-02 04:33:43 +00:00
|
|
|
if [[ $COMP_CWORD -eq 1 ]]; then
|
|
|
|
COMPREPLY+=( $(compgen -W "up down" -- "${COMP_WORDS[1]}") )
|
|
|
|
elif [[ $COMP_CWORD -eq 2 ]]; then
|
2017-09-06 18:51:41 +00:00
|
|
|
if [[ ${COMP_WORDS[1]} == up ]]; then
|
|
|
|
local old_glob="$(shopt -p nullglob)"
|
|
|
|
shopt -s nullglob
|
|
|
|
for i in /etc/wireguard/*.conf; do
|
|
|
|
i="${i##*/}"; i="${i%.conf}"
|
|
|
|
mapfile -t a < <(compgen -W "$i" -- "${COMP_WORDS[2]}")
|
|
|
|
COMPREPLY+=( "${a[@]}" )
|
|
|
|
done
|
|
|
|
eval "$old_glob"
|
|
|
|
mapfile -t a < <(compgen -f -X '!*.conf' -- "${COMP_WORDS[2]}")
|
2017-02-23 03:39:06 +00:00
|
|
|
COMPREPLY+=( "${a[@]}" )
|
2017-09-06 18:51:41 +00:00
|
|
|
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
|
2017-01-02 04:33:43 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -o filenames -o nosort -F _wg_quick_completion wg-quick
|