From cd175fd9b9addb39fbedd2cedcb58f60adbaf7b1 Mon Sep 17 00:00:00 2001 From: Mathias Schmitt Date: Sat, 15 Jan 2022 16:50:58 +0100 Subject: [PATCH 1/2] Add autocompletion script. Add the autocompletion of the different flags and options to bash. In particular, autocomplete network interfaces. --- src/bandwhich | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bandwhich diff --git a/src/bandwhich b/src/bandwhich new file mode 100644 index 000000000..4b9cdff02 --- /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 From 976d3a3d8607f47f4d3e281dac3a2b7064221a9e Mon Sep 17 00:00:00 2001 From: Mathias Schmitt Date: Sat, 15 Jan 2022 18:12:28 +0100 Subject: [PATCH 2/2] Makefile: Install autocompletion script. --- Makefile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6da0877d7..447839c30 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,10 @@ BIN=target/$(TARGET)/$(APP) BIN_DST=$(DESTDIR)$(prefix)/bin/$(APP) DOC_DST=$(DESTDIR)$(prefix)/share/man/man1/bandwhich.1 LIC_DST=$(DESTDIR)$(prefix)/share/licenses/$(APP) +AUTOCOMPLETE_DST=/usr/share/bash-completion/completions SRC = Makefile Cargo.lock Cargo.toml $(shell find src -type f -wholename 'src/*.rs') -.PHONY: all clean distclean install uninstall vendor +.PHONY: all clean distclean install uninstall vendor install_autocomplete all: $(BIN) @@ -35,12 +36,19 @@ ifeq ($(VENDOR),1) endif cargo build $(ARGS) -install: +install_autocomplete: + mkdir -p $(AUTOCOMPLETE_DST) + cp src/bandwhich $(AUTOCOMPLETE_DST)/bandwhich + +uninstall_autocomplete: + rm -f $(AUTOCOMPLETE_DST)/bandwhich + +install: install_autocomplete install -Dm755 $(BIN) $(BIN_DST) install -Dm644 docs/bandwhich.1 $(DOC_DST) install -Dm644 LICENSE.md $(LIC_DST)/LICENSE -uninstall: +uninstall: uninstall_autocomplete rm -rf $(BIN_DST) $(DOC_DST) $(LIC_DST) vendor: