commit ac1bbdd92a8d5b1d29d70bff6150c4edfce87b3d
parent c44a91ec4d9e9f1cf317f7cc044053322081d113
Author: Sean Enck <sean@ttypty.com>
Date: Tue, 11 Jan 2022 18:50:31 -0500
totp now accepts short AND once for different purposes
Diffstat:
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/cmd/lb-bash/completions.bash b/cmd/lb-bash/completions.bash
@@ -28,7 +28,7 @@ _lb() {
opts="-m $(lb ls)"
;;
"totp")
- opts="-once "$(lb totp -ls)
+ opts="-once -short "$(lb totp -ls)
if [ -n "$clip_enabled" ]; then
opts="$opts -c -clip"
fi
@@ -57,7 +57,7 @@ _lb() {
;;
"totp")
needs=0
- if [ "${COMP_WORDS[2]}" == "-once" ]; then
+ if [ "${COMP_WORDS[2]}" == "-once" ] || [ "${COMP_WORDS[2]}" == "-short" ]; then
needs=1
else
if [ -n "$clip_enabled" ]; then
diff --git a/cmd/lb-totp/main.go b/cmd/lb-totp/main.go
@@ -45,12 +45,12 @@ func clear() {
}
}
-func display(token string, clip, once bool) error {
+func display(token string, clip, once, short bool) error {
interactive, err := internal.IsInteractive()
if err != nil {
return err
}
- if once {
+ if short {
interactive = false
}
if !interactive && clip {
@@ -86,7 +86,9 @@ func display(token string, clip, once bool) error {
running := 0
lastSecond := -1
if !clip {
- clear()
+ if !once {
+ clear()
+ }
}
for {
if !first {
@@ -119,14 +121,21 @@ func display(token string, clip, once bool) error {
}
if !clip {
outputs = append(outputs, fmt.Sprintf("%s\n %s", tok, code))
- outputs = append(outputs, "-> CTRL+C to exit")
+ if !once {
+ outputs = append(outputs, "-> CTRL+C to exit")
+ }
} else {
colorize(startColor, fmt.Sprintf("\n -> %s\n", expires), endColor)
internal.CopyToClipboard(code)
return nil
}
- clear()
+ if !once {
+ clear()
+ }
colorize(startColor, strings.Join(outputs, "\n\n"), endColor)
+ if once {
+ return nil
+ }
}
}
@@ -153,15 +162,17 @@ func main() {
}
clip := false
once := false
+ short := false
if len(args) == 3 {
- if cmd != "-c" && cmd != "clip" && cmd != "-once" {
+ if cmd != "-c" && cmd != "clip" && cmd != "-once" && cmd != "-short" {
stock.Die("subcommand not supported", stock.NewBasicError("invalid sub command"))
}
- clip = cmd != "-once"
- once = !clip
+ clip = cmd == "-clip" || cmd == "-c"
+ once = cmd == "-once"
+ short = cmd == "-short"
cmd = args[2]
}
- if err := display(cmd, clip, once); err != nil {
+ if err := display(cmd, clip, once, short); err != nil {
stock.Die("failed to show totp token", err)
}
}