From 639d209d626edb6956128f55ce5f4b4920d1019e Mon Sep 17 00:00:00 2001 From: Eisfunke Date: Sat, 4 Aug 2018 15:23:07 +0200 Subject: [PATCH 1/3] Add completion script for wireguard's wg-quick --- src/_wg-quick | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/_wg-quick diff --git a/src/_wg-quick b/src/_wg-quick new file mode 100644 index 0000000..8177a1e --- /dev/null +++ b/src/_wg-quick @@ -0,0 +1,27 @@ +#compdef wg-quick +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for wg-quick (a script for easy managemant of wireguard +# VPN tunnels) (https://www.wireguard.com/) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Nicolas Lenz +# +# ------------------------------------------------------------------------------ + +# Take all configuration files (ending with .conf) from /etc/wireguard, +# remove the .conf-parts to get the inferface names +local interfaces=$(ls /etc/wireguard | \ + sed -e "/.conf$/!d" -e "s/.conf$//" 2>/dev/null) + +# The possible modes +local modes=('up\:"bring a wireguard interface up"'\ + 'down\:"tear down and remove a wireguard interface"'\ + 'save\:"save configuration of a running wireguard interface"') + +_arguments "1:mode:((${modes}))" "2:inferface:(${interfaces})" From b97156b51e219641cb6d0c044cce6fc1c58f27a4 Mon Sep 17 00:00:00 2001 From: Nicolas Lenz Date: Sun, 26 Aug 2018 20:35:37 +0200 Subject: [PATCH 2/3] Fix typo in wg-quick --- src/_wg-quick | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_wg-quick b/src/_wg-quick index 8177a1e..19ea768 100644 --- a/src/_wg-quick +++ b/src/_wg-quick @@ -24,4 +24,4 @@ local modes=('up\:"bring a wireguard interface up"'\ 'down\:"tear down and remove a wireguard interface"'\ 'save\:"save configuration of a running wireguard interface"') -_arguments "1:mode:((${modes}))" "2:inferface:(${interfaces})" +_arguments "1:mode:((${modes}))" "2:interface:(${interfaces})" From c4587d5cf785cd5351854b77f49c2f23a238d87c Mon Sep 17 00:00:00 2001 From: Nicolas Lenz Date: Sun, 26 Aug 2018 21:16:26 +0200 Subject: [PATCH 3/3] Use built-in _path_files instead of sed --- src/_wg-quick | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/_wg-quick b/src/_wg-quick index 19ea768..8de17ce 100644 --- a/src/_wg-quick +++ b/src/_wg-quick @@ -14,14 +14,12 @@ # # ------------------------------------------------------------------------------ -# Take all configuration files (ending with .conf) from /etc/wireguard, -# remove the .conf-parts to get the inferface names -local interfaces=$(ls /etc/wireguard | \ - sed -e "/.conf$/!d" -e "s/.conf$//" 2>/dev/null) - # The possible modes local modes=('up\:"bring a wireguard interface up"'\ 'down\:"tear down and remove a wireguard interface"'\ 'save\:"save configuration of a running wireguard interface"') -_arguments "1:mode:((${modes}))" "2:interface:(${interfaces})" +# 1: Complete mode +# 2: Complete interface with all .conf files in /etc/wireguard without the filename extension. +_arguments "1:mode:((${modes}))"\ + '2:interface:_path_files -W /etc/wireguard -g "*.conf(^/:r)"'