summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Schmitt <mathiaspeterhorst@gmail.com>2022-01-15 16:50:58 +0100
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-08-25 16:16:18 +0800
commit06ea4d1e61f3ae7f22534df82ca5c6173f3d1cc7 (patch)
tree2899eecac40385defff404047c9650c7ec57327e
parent0d7b410cfd9436c2ff28cb9d916b48d1a4b3e3db (diff)
Add autocompletion script.
Add the autocompletion of the different flags and options to bash. In particular, autocomplete network interfaces.
-rw-r--r--src/bandwhich31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/bandwhich b/src/bandwhich
new file mode 100644
index 0000000..4b9cdff
--- /dev/null
+++ b/src/bandwhich
@@ -0,0 +1,31 @@
+# bandwhich completion -*- shell-script -*-
+
+_bandwhich()
+{
+ local cur prev flags opts
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ flags="--addresses --connections --help --no-resolve
+ --processes --raw --show-dns --total-utilization --version"
+ opts="--dns-server --interface"
+
+ interfaces=$(ip link show | grep -o ": .*:" | sed 's/[: ]//g' | tr '\n' ' ')
+ case "${prev}" in
+ --interface)
+ COMPREPLY=( $(compgen -W "${interfaces}" -- "${cur}"))
+ return
+ ;;
+ esac
+
+ case "${cur}" in
+ --interface)
+ COMPREPLY=( $(compgen -W "${interfaces}"))
+ ;;
+ -*)
+ COMPREPLY=( $(compgen -W "${flags} ${opts}" -- "${cur}"))
+ ;;
+ esac
+} &&
+
+complete -o nospace -F _bandwhich bandwhich