commit 9ae56963ec6630e4350e3a9f3e8b137e120495a0
parent 99786ce7ac838b8cfd144c986d18675c58b8842a
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 21 Aug 2022 10:12:20 -0400
CopyTo should get the executable, it always needs it
Diffstat:
4 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -155,16 +155,11 @@ func main() {
return
}
clipboard := platform.Clipboard{}
- exe := ""
if !opts.Show {
clipboard, err = platform.NewClipboard()
if err != nil {
misc.Die("unable to get clipboard", err)
}
- exe, err = os.Executable()
- if err != nil {
- misc.Die("unable to get executable", err)
- }
}
for _, obj := range dumpData {
if opts.Show {
@@ -174,7 +169,9 @@ func main() {
fmt.Println(obj.Value)
continue
}
- clipboard.CopyTo(obj.Value, exe)
+ if err := clipboard.CopyTo(obj.Value); err != nil {
+ misc.Die("clipboard failed", err)
+ }
}
case "clear":
if err := subcommands.ClearClipboardCallback(); err != nil {
diff --git a/internal/platform/clipboard.go b/internal/platform/clipboard.go
@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"os/exec"
- "path/filepath"
"strconv"
"github.com/enckse/lockbox/internal/inputs"
@@ -73,13 +72,18 @@ func NewClipboard() (Clipboard, error) {
}
// CopyTo will copy to clipboard, if non-empty will clear later.
-func (c Clipboard) CopyTo(value, executable string) {
+func (c Clipboard) CopyTo(value string) error {
+ exe, err := os.Executable()
+ if err != nil {
+ return err
+ }
cmd, args := c.Args(true)
pipeTo(cmd, value, true, args...)
if value != "" {
fmt.Printf("clipboard will clear in %d seconds\n", c.MaxTime)
- pipeTo(filepath.Join(filepath.Dir(executable), "lb"), value, false, "clear")
+ pipeTo(exe, value, false, "clear")
}
+ return nil
}
// Args returns clipboard args for execution.
diff --git a/internal/subcommands/clear.go b/internal/subcommands/clear.go
@@ -2,7 +2,6 @@
package subcommands
import (
- "os"
"os/exec"
"strings"
"time"
@@ -35,10 +34,5 @@ func ClearClipboardCallback() error {
return nil
}
}
- exe, err := os.Executable()
- if err != nil {
- return err
- }
- clipboard.CopyTo("", exe)
- return nil
+ return clipboard.CopyTo("")
}
diff --git a/internal/subcommands/totp.go b/internal/subcommands/totp.go
@@ -107,10 +107,6 @@ func display(token string, args cli.Arguments) error {
if err != nil {
return err
}
- exe, err := os.Executable()
- if err != nil {
- return err
- }
totpToken := string(val)
if !interactive {
code, err := otp.GenerateCode(totpToken, time.Now())
@@ -181,8 +177,7 @@ func display(token string, args cli.Arguments) error {
}
} else {
fmt.Printf("-> %s\n", expires)
- clipboard.CopyTo(code, exe)
- return nil
+ return clipboard.CopyTo(code)
}
if !args.Once {
clear()