lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 7cceb5ba2795c7ac9ebe2e223c8971fa238e920a
parent 391d141f7f3da23cf85feb203ceb018f446b9de0
Author: Sean Enck <sean@ttypty.com>
Date:   Sun, 12 Dec 2021 18:34:47 -0500

fixing up totp subcommand

Diffstat:
Mcmd/lb-bash/completions.bash | 10+++++-----
Mcmd/lb-totp/main.go | 15++++++++++-----
Mmeson.build | 2+-
Mtests/run.sh | 2+-
4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/cmd/lb-bash/completions.bash b/cmd/lb-bash/completions.bash @@ -1,7 +1,7 @@ # bash completion for lb -*- shell-script -*- _is_clip() { - if [ "$1" == "-c" ] || [ "$1" == "clip" ]; then + if [ "$1" == "-c" ] || [ "$1" == "{2}clip" ]; then echo 1 else echo 0 @@ -28,9 +28,9 @@ _lb() { opts="-m $(lb ls)" ;; "totp") - opts=$(lb totp ls) + opts="-once "$(lb totp -ls) if [ -n "$clip_enabled" ]; then - opts="$opts$clip_enabled" + opts="$opts -c -clip" fi ;; "pwgen") @@ -38,7 +38,7 @@ _lb() { ;; "-c" | "show" | "rm" | "clip") opts=$(lb ls) - if [ $(_is_clip "${COMP_WORDS[1]}") == 1 ]; then + if [ $(_is_clip "${COMP_WORDS[1]}" "") == 1 ]; then if [ -z "$clip_enabled" ]; then opts="" fi @@ -57,7 +57,7 @@ _lb() { ;; "totp") if [ -n "$clip_enabled" ]; then - if [ $(_is_clip "${COMP_WORDS[2]}") == 1 ]; then + if [ $(_is_clip "${COMP_WORDS[2]}" "-") == 1 ]; then opts=$(lb totp ls) fi fi diff --git a/cmd/lb-totp/main.go b/cmd/lb-totp/main.go @@ -45,11 +45,14 @@ func clear() { } } -func display(token string, clip bool) error { +func display(token string, clip, once bool) error { interactive, err := internal.IsInteractive() if err != nil { return err } + if once { + interactive = false + } if !interactive && clip { return stock.NewBasicError("clipboard not available in non-interactive mode") } @@ -137,7 +140,7 @@ func main() { stock.Die("subkey required", stock.NewBasicError("invalid arguments")) } cmd := args[1] - if cmd == "list" || cmd == "ls" { + if cmd == "-list" || cmd == "-ls" { result, err := list() if err != nil { stock.Die("invalid list response", err) @@ -149,14 +152,16 @@ func main() { return } clip := false + once := false if len(args) == 3 { - if cmd != "-c" && cmd != "clip" { + if cmd != "-c" && cmd != "clip" && cmd != "-once" { stock.Die("subcommand not supported", stock.NewBasicError("invalid sub command")) } - clip = true + clip = cmd != "-once" + once = !clip cmd = args[2] } - if err := display(cmd, clip); err != nil { + if err := display(cmd, clip, once); err != nil { stock.Die("failed to show totp token", err) } } diff --git a/meson.build b/meson.build @@ -18,7 +18,7 @@ foreach p : progs p, output: p, build_by_default: true, - input: in_files, + input: target_files, command: [ golang, 'build', flags, '-o','@OUTPUT@', cmd_file], ) endforeach diff --git a/tests/run.sh b/tests/run.sh @@ -40,7 +40,7 @@ _run() { "$BIN/lb" show keys/one2 "$BIN/lb" show keys2/three echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert totp/test - "$BIN/lb-totp" ls + "$BIN/lb-totp" -ls "$BIN/lb-totp" test | tr '[:digit:]' 'X' "$BIN/lb-diff" bin/lb/keys/one.lb bin/lb/keys/one2.lb yes 2>/dev/null | "$BIN/lb" rm keys2/three