diff options
| author | Shulhan <ms@kilabit.info> | 2022-09-17 16:57:12 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-09-17 17:59:21 +0700 |
| commit | 397789cea60237f357476c86df96cd234e7b37eb (patch) | |
| tree | c984105fdf9802019370d1e584f50e4ab8f47b39 /etc/bash_completion.d | |
| parent | b2a4fb1351628323d9a16c74fc0771a7c451d89e (diff) | |
| download | bin.sh-397789cea60237f357476c86df96cd234e7b37eb.tar.xz | |
all: add script wg-activate.sh
The wg-activate.sh is script that activate only one wireguard connection
from list of configuration in /etc/wireguard/*.conf or turning off
all of them if no parameter is given.
Diffstat (limited to 'etc/bash_completion.d')
| -rw-r--r-- | etc/bash_completion.d/wg-activate | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/etc/bash_completion.d/wg-activate b/etc/bash_completion.d/wg-activate new file mode 100644 index 0000000..a0f5486 --- /dev/null +++ b/etc/bash_completion.d/wg-activate @@ -0,0 +1,24 @@ +#/usr/bin/env bash +## SPDX-FileCopyrightText: 2022 M. Shulhan <ms@kilabit.info> +## SPDX-License-Identifier: GPL-3.0-or-later + +_wg-activate_completions() +{ + confs=$(find -L /etc/wireguard -maxdepth 1 -type f -name "*.conf" -print) + + names=() + for f in $confs; do + got=$(basename "${f%.conf}") + names+=("$got") + done + + if [[ -z "${COMP_WORDS[1]}" ]]; then + COMPREPLY=("${names[@]}") + return + fi + + words="${names[@]}" + COMPREPLY=($(compgen -W "$words" -- "${COMP_WORDS[1]}")) +} + +complete -F _wg-activate_completions wg-activate.sh |
