aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Fisher <tadfisher@gmail.com>2018-10-20 19:37:26 -0700
committerGitHub <noreply@github.com>2018-10-20 19:37:26 -0700
commit234a5610656bc5eee348c8a323653964796fb498 (patch)
tree21a52a2142ebf43e764942e801b3768db085809f
parent4db4feb628fe84558283a30ea52435610dd2ca12 (diff)
parent96ee01de6cc2b8bbd784e984a6438587890c4d28 (diff)
Merge pull request #91 from crt/feature/bash_completion
Add bash_completion support
-rw-r--r--Makefile4
-rw-r--r--pass-otp.bash.completion26
2 files changed, 30 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 402dc39..a48cad1 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ DESTDIR ?=
LIBDIR ?= $(PREFIX)/lib
SYSTEM_EXTENSION_DIR ?= $(LIBDIR)/password-store/extensions
MANDIR ?= $(PREFIX)/share/man
+BASHCOMPDIR ?= /etc/bash_completion.d
all:
@echo "pass-$(PROG) is a shell script and does not need compilation, it can be simply executed."
@@ -17,6 +18,8 @@ install:
@install -v -d "$(DESTDIR)$(MANDIR)/man1" && install -m 0644 -v pass-$(PROG).1 "$(DESTDIR)$(MANDIR)/man1/pass-$(PROG).1"
@install -v -d "$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/"
@install -v -m0755 $(PROG).bash "$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/$(PROG).bash"
+ @install -v -d "$(DESTDIR)$(BASHCOMPDIR)/"
+ @install -v -m 644 pass-otp.bash.completion "$(DESTDIR)$(BASHCOMPDIR)/pass-otp"
@echo
@echo "pass-$(PROG) is installed succesfully"
@echo
@@ -25,6 +28,7 @@ uninstall:
@rm -vrf \
"$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/$(PROG).bash" \
"$(DESTDIR)$(MANDIR)/man1/pass-$(PROG).1"
+ "$(DESTDIR)$(BASHCOMPDIR)/pass-otp"
lint:
shellcheck -s bash $(PROG).bash
diff --git a/pass-otp.bash.completion b/pass-otp.bash.completion
new file mode 100644
index 0000000..5b13dcc
--- /dev/null
+++ b/pass-otp.bash.completion
@@ -0,0 +1,26 @@
+PASSWORD_STORE_EXTENSION_COMMANDS+=(otp)
+
+__password_store_extension_complete_otp() {
+ if [[ $COMP_CWORD -gt 2 ]]; then
+ case "${COMP_WORDS[2]}" in
+ insert|append)
+ COMPREPLY+=($(compgen -W "-e --echo -f --force -s --secret -i --issuer -a --account" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ uri)
+ COMPREPLY+=($(compgen -W "-c --clip -q --qrcode" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ validate)
+ _pass_complete_entries
+ ;;
+ *)
+ COMPREPLY+=($(compgen -W "-h --help" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ esac
+ else
+ COMPREPLY+=($(compgen -W "insert append uri validate -h --help -c --clip" -- ${cur}))
+ _pass_complete_entries 1
+ fi
+}