diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | _AUR/PKGBUILD | 2 | ||||
| -rw-r--r-- | _sys/etc/bash_completion.d/gotp | 57 |
3 files changed, 59 insertions, 1 deletions
@@ -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 |
