commit 05f24270d8d68a37f64f304e082e75f4c89416b9
parent 618aa3b074418c60aace210187e0ad86d28fbfc0
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 18 Dec 2022 11:44:01 -0500
support osc within lb
Diffstat:
7 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -313,6 +313,9 @@ func clearClipboard(args []string) error {
if err != nil {
return err
}
+ if clipboard.IsInternal() {
+ return nil
+ }
pCmd, pArgs := clipboard.Args(false)
val = strings.TrimSpace(val)
for idx < clipboard.MaxTime {
diff --git a/cmd/vers.txt b/cmd/vers.txt
@@ -1 +1 @@
-v22.12.01
-\ No newline at end of file
+v22.12.02
+\ No newline at end of file
diff --git a/go.mod b/go.mod
@@ -3,6 +3,7 @@ module github.com/enckse/lockbox
go 1.19
require (
+ github.com/aymanbagabas/go-osc52 v1.2.1
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pquerna/otp v1.4.0
github.com/tobischo/gokeepasslib/v3 v3.4.1
diff --git a/go.sum b/go.sum
@@ -2,6 +2,8 @@ github.com/aead/argon2 v0.0.0-20180111183520-a87724528b07 h1:i9/M2RadeVsPBMNwXFi
github.com/aead/argon2 v0.0.0-20180111183520-a87724528b07/go.mod h1:Tnm/osX+XXr9R+S71o5/F0E60sRkPVALdhWw25qPImQ=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
+github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E=
+github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -39,6 +39,7 @@ const (
ClipPasteEnv = clipBaseEnv + "PASTE"
// ClipCopyEnv allows overriding the clipboard copy command
ClipCopyEnv = clipBaseEnv + "COPY"
+ clipOSCEnv = clipBaseEnv + "OSC"
isYes = "yes"
isNo = "no"
defaultTOTPField = "totp"
@@ -200,6 +201,10 @@ func isYesNoEnv(defaultValue bool, env string) (bool, error) {
return false, fmt.Errorf("invalid yes/no env value for %s", env)
}
+func IsClipOSC() (bool, error) {
+ return isYesNoEnv(false, clipOSCEnv)
+}
+
// IsNoTOTP indicates if TOTP is disabled
func IsNoTOTP() (bool, error) {
return isYesNoEnv(false, noTOTPEnv)
@@ -285,5 +290,6 @@ func ListEnvironmentVariables(showValues bool) []string {
results = append(results, e.formatEnvironmentVariable(false, PlatformEnv, detectedValue, "override the detected platform", []string{MacOSPlatform, LinuxWaylandPlatform, LinuxXPlatform, WindowsLinuxPlatform}))
results = append(results, e.formatEnvironmentVariable(false, noTOTPEnv, isNo, "disable TOTP integrations", isYesNoArgs))
results = append(results, e.formatEnvironmentVariable(false, HookDirEnv, "", "the path to hooks to execute on actions against the database", []string{"directory"}))
+ results = append(results, e.formatEnvironmentVariable(false, clipOSCEnv, isNo, "enable OSC52 clipboard mode", isYesNoArgs))
return results
}
diff --git a/internal/inputs/env_test.go b/internal/inputs/env_test.go
@@ -162,7 +162,7 @@ func TestListVariables(t *testing.T) {
known[trim] = struct{}{}
}
l := len(known)
- if l != 16 {
+ if l != 17 {
t.Errorf("invalid env count, outdated? %d", l)
}
}
diff --git a/internal/platform/clipboard.go b/internal/platform/clipboard.go
@@ -8,6 +8,7 @@ import (
"os/exec"
"strings"
+ osc "github.com/aymanbagabas/go-osc52"
"github.com/enckse/lockbox/internal/inputs"
"github.com/google/shlex"
)
@@ -15,18 +16,23 @@ import (
type (
// Clipboard represent system clipboard operations.
Clipboard struct {
- copying []string
- pasting []string
- MaxTime int
+ copying []string
+ pasting []string
+ MaxTime int
+ isInternal bool
}
)
+func (c Clipboard) IsInternal() bool {
+ return c.isInternal
+}
+
func newClipboard(copying, pasting []string) (Clipboard, error) {
max, err := inputs.GetClipboardMax()
if err != nil {
return Clipboard{}, err
}
- return Clipboard{copying: copying, pasting: pasting, MaxTime: max}, nil
+ return Clipboard{copying: copying, pasting: pasting, MaxTime: max, isInternal: false}, nil
}
func overrideCommand(v string) ([]string, error) {
@@ -57,6 +63,14 @@ func NewClipboard() (Clipboard, error) {
if overrideCopy != nil && overridePaste != nil {
return newClipboard(overrideCopy, overridePaste)
}
+ isOSC, err := inputs.IsClipOSC()
+ if err != nil {
+ return Clipboard{}, err
+ }
+ if isOSC {
+ c := Clipboard{isInternal: true}
+ return c, nil
+ }
sys, err := NewPlatform()
if err != nil {
return Clipboard{}, err
@@ -91,6 +105,10 @@ func NewClipboard() (Clipboard, error) {
// CopyTo will copy to clipboard, if non-empty will clear later.
func (c Clipboard) CopyTo(value string) error {
+ if c.isInternal {
+ osc.Copy(value)
+ return nil
+ }
exe, err := os.Executable()
if err != nil {
return err