2017-11-30 16:23:50 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2020-01-02 19:52:25 +01:00
|
|
|
# Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2017-01-02 05:33:43 +01:00
|
|
|
|
|
|
|
_wg_quick_completion() {
|
2018-05-23 15:17:41 +02:00
|
|
|
local p i a search_paths old_glob
|
2018-05-23 15:08:30 +02:00
|
|
|
search_paths=( /etc/wireguard )
|
|
|
|
|
2018-05-23 15:17:41 +02:00
|
|
|
old_glob="$(shopt -p nullglob)"
|
|
|
|
shopt -s nullglob
|
|
|
|
|
2018-05-23 15:08:30 +02:00
|
|
|
[[ $OSTYPE == *freebsd* || $OSTYPE == *darwin* ]] && search_paths+=( /usr/local/etc/wireguard )
|
|
|
|
|
2017-01-02 05:33:43 +01:00
|
|
|
if [[ $COMP_CWORD -eq 1 ]]; then
|
|
|
|
COMPREPLY+=( $(compgen -W "up down" -- "${COMP_WORDS[1]}") )
|
|
|
|
elif [[ $COMP_CWORD -eq 2 ]]; then
|
2017-09-06 20:51:41 +02:00
|
|
|
if [[ ${COMP_WORDS[1]} == up ]]; then
|
2018-05-23 15:08:30 +02:00
|
|
|
for p in "${search_paths[@]}"; do
|
|
|
|
for i in "$p"/*.conf; do
|
|
|
|
i="${i##*/}"; i="${i%.conf}"
|
|
|
|
mapfile -t a < <(compgen -W "$i" -- "${COMP_WORDS[2]}")
|
|
|
|
COMPREPLY+=( "${a[@]}" )
|
|
|
|
done
|
2017-09-06 20:51:41 +02:00
|
|
|
done
|
|
|
|
mapfile -t a < <(compgen -f -X '!*.conf' -- "${COMP_WORDS[2]}")
|
2017-02-23 04:39:06 +01:00
|
|
|
COMPREPLY+=( "${a[@]}" )
|
2017-09-06 20:51:41 +02:00
|
|
|
mapfile -t a < <(compgen -d -- "${COMP_WORDS[2]}")
|
|
|
|
COMPREPLY+=( "${a[@]}" )
|
|
|
|
elif [[ ${COMP_WORDS[1]} == down ]]; then
|
2018-05-23 15:17:41 +02:00
|
|
|
if [[ $OSTYPE == *openbsd* || $OSTYPE == *darwin* ]]; then
|
|
|
|
for i in /var/run/wireguard/*.name; do
|
|
|
|
i="${i##*/}"; i="${i%.name}"
|
|
|
|
mapfile -t a < <(compgen -W "$i" -- "${COMP_WORDS[2]}")
|
|
|
|
COMPREPLY+=( "${a[@]}" )
|
|
|
|
done
|
|
|
|
else
|
|
|
|
COMPREPLY+=( $(compgen -W "$(wg show interfaces)" -- "${COMP_WORDS[2]}") )
|
|
|
|
fi
|
2017-09-06 20:51:41 +02:00
|
|
|
fi
|
2017-01-02 05:33:43 +01:00
|
|
|
fi
|
2018-05-23 15:17:41 +02:00
|
|
|
eval "$old_glob"
|
2017-01-02 05:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -o filenames -o nosort -F _wg_quick_completion wg-quick
|