From ac323e8b4b9940d9b05b29f82a8f2d00563c7942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Apeland?= Date: Wed, 27 Nov 2019 16:09:16 +0100 Subject: [PATCH] contrib: bash: completion.bash: add Bash completion for options --- Makefile | 49 ++++++++++++++++++++---------------- contrib/bash/completion.bash | 14 +++++++++++ 2 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 contrib/bash/completion.bash diff --git a/Makefile b/Makefile index 44ab19f..118286f 100644 --- a/Makefile +++ b/Makefile @@ -8,27 +8,28 @@ # build target for simplicity. # -BIN = btrbk -BIN_LINKS = lsbtr -CONFIGS = btrbk.conf.example -DOCS = ChangeLog \ - README.md -SCRIPTS = ssh_filter_btrbk.sh \ - contrib/cron/btrbk-mail \ - contrib/cron/btrbk-verify \ - contrib/migration/raw_suffix2sidecar \ - contrib/crypt/kdf_pbkdf2.py +BIN = btrbk +BIN_LINKS = lsbtr +CONFIGS = btrbk.conf.example +DOCS = ChangeLog \ + README.md +SCRIPTS = ssh_filter_btrbk.sh \ + contrib/cron/btrbk-mail \ + contrib/cron/btrbk-verify \ + contrib/migration/raw_suffix2sidecar \ + contrib/crypt/kdf_pbkdf2.py -PN = btrbk -PREFIX ?= /usr -CONFDIR = /etc -CRONDIR = /etc/cron.daily -BINDIR = $(PREFIX)/bin -DOCDIR = $(PREFIX)/share/doc/$(PN) -SCRIPTDIR = $(PREFIX)/share/$(PN)/scripts -SYSTEMDDIR = $(PREFIX)/lib/systemd/system -MAN1DIR = $(PREFIX)/share/man/man1 -MAN5DIR = $(PREFIX)/share/man/man5 +PN = btrbk +PREFIX ?= /usr +CONFDIR = /etc +CRONDIR = /etc/cron.daily +BINDIR = $(PREFIX)/bin +DOCDIR = $(PREFIX)/share/doc/$(PN) +SCRIPTDIR = $(PREFIX)/share/$(PN)/scripts +SYSTEMDDIR = $(PREFIX)/lib/systemd/system +BASHCOMPDIR = $(PREFIX)/share/bash-completion/completions +MAN1DIR = $(PREFIX)/share/man/man1 +MAN5DIR = $(PREFIX)/share/man/man5 ifeq ($(COMPRESS), yes) DOCS := $(addsuffix .gz,$(DOCS)) @@ -42,12 +43,13 @@ replace_vars = sed \ -e "s|@DOCDIR@|$(DOCDIR)|g" \ -e "s|@SCRIPTDIR@|$(SCRIPTDIR)|g" \ -e "s|@SYSTEMDDIR@|$(SYSTEMDDIR)|g" \ + -e "s|@BASHCOMPDIR@|$(BASHCOMPDIR)|g" \ -e "s|@MAN1DIR@|$(MAN1DIR)|g" \ -e "s|@MAN5DIR@|$(MAN5DIR)|g" all: man -install: install-bin install-bin-links install-etc install-systemd install-share install-man install-doc +install: install-bin install-bin-links install-etc install-completion install-systemd install-share install-man install-doc install-bin: @echo 'installing binary...' @@ -65,6 +67,11 @@ install-etc: install -d -m 755 "$(DESTDIR)$(CONFDIR)/btrbk" install -p -m 644 $(CONFIGS) "$(DESTDIR)$(CONFDIR)/btrbk" +install-completion: + @echo 'installing bash completion...' + install -d -m 755 "$(DESTDIR)$(BASHCOMPDIR)" + install -p -m 644 contrib/bash/completion.bash "$(DESTDIR)$(BASHCOMPDIR)/$(BIN)" + install-systemd: @echo 'installing systemd service units...' install -d -m 755 "$(DESTDIR)$(SYSTEMDDIR)" diff --git a/contrib/bash/completion.bash b/contrib/bash/completion.bash new file mode 100644 index 0000000..cd77e0c --- /dev/null +++ b/contrib/bash/completion.bash @@ -0,0 +1,14 @@ +_btrbk() +{ + local cur prev words cword split + _init_completion -s || return + + $split && return + + if [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + [[ $COMPREPLY == *= ]] && compopt -o nospace + fi +} && complete -F _btrbk btrbk + +# ex: filetype=bash