lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 160f6e9cf0aa799004fad0599b36c5cae31843be
parent 34ec77088a0e0f0b54377008d47a60b11fbde486
Author: Sean Enck <sean@ttypty.com>
Date:   Mon, 19 Jul 2021 18:30:14 -0400

completions wrapper to generate bash completions

Diffstat:
MMakefile | 2+-
Acmd/bash/completions.bash | 39+++++++++++++++++++++++++++++++++++++++
Acmd/bash/main.go | 15+++++++++++++++
Dlb.bash | 37-------------------------------------
4 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ BIN := bin/ FLG := -ldflags '-linkmode external -extldflags $(LDFLAGS) -w' -trimpath -buildmode=pie -mod=readonly -modcacherw -CMD := $(BIN)lb-diff $(BIN)lb-stats $(BIN)lb-rekey $(BIN)lb-rw $(BIN)lb $(BIN)lb-totp $(BIN)lb-pwgen +CMD := $(shell ls cmd | sed "s|^|$(BIN)lb-|g") all: $(CMD) diff --git a/cmd/bash/completions.bash b/cmd/bash/completions.bash @@ -0,0 +1,39 @@ +# bash completion for lb -*- shell-script -*- + +_lb() { + local cur opts + cur=${COMP_WORDS[COMP_CWORD]} + if [ $COMP_CWORD -eq 1 ]; then + opts="ls clip show -c insert rm rekey totp list pwgen stats" + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + else + if [ $COMP_CWORD -eq 2 ]; then + case ${COMP_WORDS[1]} in + "insert") + opts="-m $(lb ls)" + ;; + "totp") + opts=$(lb totp ls) + ;; + "pwgen") + opts="-length -transform -special" + ;; + "-c" | "show" | "rm" | "clip" | "stats") + opts=$(lb ls) + ;; + esac + fi + if [ $COMP_CWORD -eq 3 ] && [ "${COMP_WORDS[1]}" == "insert" ]; then + if [ "${COMP_WORDS[2]}" == "-m" ]; then + opts=$(lb ls) + else + opts="-m" + fi + fi + if [ ! -z "$opts" ]; then + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + fi + fi +} + +complete -F _lb -o bashdefault -o default lb diff --git a/cmd/bash/main.go b/cmd/bash/main.go @@ -0,0 +1,15 @@ +package main + +import ( + _ "embed" + "fmt" +) + +var ( + //go:embed completions.bash + completions string +) + +func main() { + fmt.Println(completions) +} diff --git a/lb.bash b/lb.bash @@ -1,37 +0,0 @@ -_lb() { - local cur opts - cur=${COMP_WORDS[COMP_CWORD]} - if [ $COMP_CWORD -eq 1 ]; then - opts="ls clip show -c insert rm rekey totp list pwgen stats" - COMPREPLY=( $(compgen -W "$opts" -- $cur) ) - else - if [ $COMP_CWORD -eq 2 ]; then - case ${COMP_WORDS[1]} in - "insert") - opts="-m $(lb ls)" - ;; - "totp") - opts=$(lb totp ls) - ;; - "pwgen") - opts="-length -transform -special" - ;; - "-c" | "show" | "rm" | "clip" | "stats") - opts=$(lb ls) - ;; - esac - fi - if [ $COMP_CWORD -eq 3 ] && [ "${COMP_WORDS[1]}" == "insert" ]; then - if [ "${COMP_WORDS[2]}" == "-m" ]; then - opts=$(lb ls) - else - opts="-m" - fi - fi - if [ ! -z "$opts" ]; then - COMPREPLY=( $(compgen -W "$opts" -- $cur) ) - fi - fi -} - -complete -F _lb -o bashdefault -o default lb