From 54230d76e656f87ccbc2cb344350afa02918ae61 Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Thu, 28 Mar 2024 19:11:46 +0100 Subject: [PATCH] add bash completion --- Makefile | 4 +++- bash-completion | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 bash-completion diff --git a/Makefile b/Makefile index 7957e98..e298e15 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SCANNER := wayland-scanner PREFIX=/usr/local BINDIR=$(PREFIX)/bin MANDIR=$(PREFIX)/share/man +BASHCOMPDIR=$(PREFIX)/share/bash-completion/completions CFLAGS+=-Wall -Werror -Wextra -Wpedantic -Wno-unused-parameter -Wconversion -Wformat-security -Wformat -Wsign-conversion -Wfloat-conversion -Wunused-result -Wno-strict-prototypes LIBS=-lwayland-client @@ -25,13 +26,14 @@ install: wlopm install wlopm $(DESTDIR)$(BINDIR) install -d $(DESTDIR)$(MANDIR)/man1 install -m 644 wlopm.1 $(DESTDIR)$(MANDIR)/man1 + install bash-completion $(DESTDIR)$(BASHCOMPDIR)/wlopm uninstall: $(RM) $(DESTDIR)$(BINDIR)/wlopm $(RM) $(DESTDIR)$(MANDIR)/man1/wlopm.1 + $(RM) $(DESTDIR)$(BASHCOMPDIR)/wlopm clean: $(RM) wlopm $(GEN) $(OBJ) .PHONY: clean install - diff --git a/bash-completion b/bash-completion new file mode 100644 index 0000000..631ddd0 --- /dev/null +++ b/bash-completion @@ -0,0 +1,14 @@ +function __wlopm_completion () +{ + case "${COMP_WORDS[-2]}" in + "--on"|"--off"|"--toggle") + OPTS="$(wlopm | cut -d' ' -f1 | tr '\n' ' ')" + ;; + + *) + OPTS="-h --help -j --json -v --version --on --off --toggle" + ;; + esac + COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[${COMP_CWORD}]}")) +} +complete -F __wlopm_completion wlopm