aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-09-18 01:02:33 +0700
committerShulhan <ms@kilabit.info>2022-09-18 01:04:01 +0700
commit80ff9b1c6c1506d29b9e8f4e43597e4b6e540b05 (patch)
tree591c9430a3b687e244833e16f56a340bb1c77ab8
parent403eb5ddbdbfd1d26fe2fa5710660230d7bb7e58 (diff)
downloadgotp-80ff9b1c6c1506d29b9e8f4e43597e4b6e540b05.tar.xz
all: add bash completion script
-rw-r--r--Makefile1
-rw-r--r--_AUR/PKGBUILD2
-rw-r--r--_sys/etc/bash_completion.d/gotp57
3 files changed, 59 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 1f46a8e..958a8b3 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,7 @@ build:
install: build
install -D _sys/usr/bin/gotp $(DESTDIR)/usr/bin/gotp
+ install -Dm644 _sys/etc/bash_completion.d/gotp $(DESTDIR)/etc/bash_completion.d/gotp
install -Dm644 COPYING $(DESTDIR)/usr/share/licenses/gotp/COPYING
serve-doc:
diff --git a/_AUR/PKGBUILD b/_AUR/PKGBUILD
index 601342b..06fa47e 100644
--- a/_AUR/PKGBUILD
+++ b/_AUR/PKGBUILD
@@ -3,7 +3,7 @@
## SPDX-License-Identifier: GPL-3.0-or-later
pkgname=gotp-git
-pkgver=0.2.2.r2.g008f3a5
+pkgver=0.2.2.r3.gaab7eb0
pkgrel=1
pkgdesc="A command line interface to manage and generate Time-based One Time Password (TOTP)"
diff --git a/_sys/etc/bash_completion.d/gotp b/_sys/etc/bash_completion.d/gotp
new file mode 100644
index 0000000..b330a20
--- /dev/null
+++ b/_sys/etc/bash_completion.d/gotp
@@ -0,0 +1,57 @@
+#/usr/bin/env bash
+## SPDX-FileCopyrightText: 2022 M. Shulhan <ms@kilabit.info>
+## SPDX-License-Identifier: GPL-3.0-or-later
+
+suggest_key() {
+ keys=($(gotp list))
+ if [[ -z $1 ]]; then
+ COMPREPLY=("${keys[@]}")
+ else
+ local list="${keys[@]}"
+ local got=($(compgen -W "$list" -- "$1"))
+ COMPREPLY=("${got[@]}")
+ fi
+}
+
+_gotp_completions()
+{
+ commands=("add" "gen" "import" "list" "remove" "rename")
+
+ local len=${#COMP_WORDS[@]}
+ local cmd=${COMP_WORDS[1]}
+ local key=${COMP_WORDS[2]}
+
+ case "$cmd" in
+ add)
+ ;;
+ gen)
+ if [[ $len == 3 ]]; then
+ suggest_key "$key"
+ fi
+ ;;
+ import)
+ ;;
+ list)
+ ;;
+ remove)
+ if [[ $len == 3 ]]; then
+ suggest_key "$key"
+ fi
+ ;;
+ rename)
+ if [[ $len == 3 ]]; then
+ suggest_key "$key"
+ fi
+ ;;
+ *)
+ if [[ -z $cmd ]]; then
+ COMPREPLY=("${commands[@]}")
+ else
+ list="${commands[@]}"
+ COMPREPLY=($(compgen -W "$list" -- "$cmd"))
+ fi
+ ;;
+ esac
+}
+
+complete -F _gotp_completions gotp