Use an external command for clipboard
This commit is contained in:
parent
e8bf42dd17
commit
cf346ed025
12
cmd/root.go
12
cmd/root.go
@ -12,7 +12,6 @@ import (
|
|||||||
gap "github.com/muesli/go-app-paths"
|
gap "github.com/muesli/go-app-paths"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"golang.design/x/clipboard"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
@ -47,10 +46,6 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := clipboard.Init()
|
|
||||||
if err != nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
rootCmd.Version = Version
|
rootCmd.Version = Version
|
||||||
initConfig()
|
initConfig()
|
||||||
}
|
}
|
||||||
@ -89,7 +84,7 @@ func initConfig() {
|
|||||||
if createConfig {
|
if createConfig {
|
||||||
_, err := os.Stat(firstDir)
|
_, err := os.Stat(firstDir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
err := os.Mkdir(firstDir, 0755)
|
err := os.Mkdir(firstDir, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -105,5 +100,10 @@ func initConfig() {
|
|||||||
db = util.PromptUserTrimmed("Path to KeePass Database:")
|
db = util.PromptUserTrimmed("Path to KeePass Database:")
|
||||||
viper.Set("database", db)
|
viper.Set("database", db)
|
||||||
}
|
}
|
||||||
|
cbCmd := viper.GetString("clipboard-command")
|
||||||
|
if cbCmd == "" {
|
||||||
|
cbCmd = util.PromptUserTrimmed("Copy to Clipboard Command:")
|
||||||
|
viper.Set("clipboard-command", cbCmd)
|
||||||
|
}
|
||||||
viper.WriteConfig()
|
viper.WriteConfig()
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.bullercodeworks.com/brian/keepass-cli/models"
|
"git.bullercodeworks.com/brian/keepass-cli/models"
|
||||||
|
"git.bullercodeworks.com/brian/keepass-cli/util"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,6 +26,7 @@ func init() {
|
|||||||
func runTestCmd(_ *cobra.Command, args []string) error {
|
func runTestCmd(_ *cobra.Command, args []string) error {
|
||||||
models.LoadFrequencies()
|
models.LoadFrequencies()
|
||||||
fmt.Println(args)
|
fmt.Println(args)
|
||||||
|
util.WriteToClipboard(strings.Join(args, " "))
|
||||||
/*
|
/*
|
||||||
var db *models.KeePassDB
|
var db *models.KeePassDB
|
||||||
pass, err := util.PromptUserForPassword("Master Password")
|
pass, err := util.PromptUserForPassword("Master Password")
|
||||||
|
12
go.mod
12
go.mod
@ -2,20 +2,17 @@ module git.bullercodeworks.com/brian/keepass-cli
|
|||||||
|
|
||||||
go 1.22.3
|
go 1.22.3
|
||||||
|
|
||||||
replace github.com/tobischo/gokeepasslib => ../../../github.com/tobischo/gokeepasslib
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/atotto/clipboard v0.1.4
|
|
||||||
github.com/muesli/go-app-paths v0.2.2
|
github.com/muesli/go-app-paths v0.2.2
|
||||||
github.com/spf13/cobra v1.8.0
|
github.com/spf13/cobra v1.8.0
|
||||||
github.com/spf13/viper v1.18.2
|
github.com/spf13/viper v1.18.2
|
||||||
github.com/tobischo/gokeepasslib v1.0.0
|
github.com/tobischo/gokeepasslib v1.0.0
|
||||||
golang.design/x/clipboard v0.7.0
|
|
||||||
golang.org/x/term v0.20.0
|
golang.org/x/term v0.20.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
@ -28,16 +25,11 @@ require (
|
|||||||
github.com/spf13/afero v1.11.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/spf13/cast v1.6.0 // indirect
|
github.com/spf13/cast v1.6.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/stretchr/testify v1.9.0 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/tobischo/argon2 v0.1.0 // indirect
|
|
||||||
github.com/tobischo/gokeepasslib/v3 v3.6.0 // indirect
|
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/crypto v0.23.0 // indirect
|
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||||
golang.org/x/exp/shiny v0.0.0-20240506185415-9bf2ced13842 // indirect
|
|
||||||
golang.org/x/image v0.14.0 // indirect
|
|
||||||
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
|
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
golang.org/x/text v0.15.0 // indirect
|
golang.org/x/text v0.15.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
18
go.sum
18
go.sum
@ -1,5 +1,3 @@
|
|||||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
|
||||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -62,26 +60,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
|||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||||
github.com/tobischo/argon2 v0.1.0 h1:mwAx/9DK/4rP0xzNifb/XMAf43dU3eG1B3aeF88qu4Y=
|
github.com/tobischo/gokeepasslib v1.0.0 h1:+cvOvPNoaop/8CL2P6Up9Ly1ih8oarkS/0QoBWQeAlM=
|
||||||
github.com/tobischo/argon2 v0.1.0/go.mod h1:4NLmLFwhWPbT66nRZNgcktV/mibJ6fESoeEp43h9GRw=
|
github.com/tobischo/gokeepasslib v1.0.0/go.mod h1:rmRsvAEXwfdT+WMzMjvM2JJiDKRvccJ7+s3MmyK8XC4=
|
||||||
github.com/tobischo/gokeepasslib/v3 v3.6.0 h1:7SVV7WNvW8EGb0UYETj2IwjbgfqKEmij2gUnndXSIxk=
|
|
||||||
github.com/tobischo/gokeepasslib/v3 v3.6.0/go.mod h1:/T7C3zga6hsbLoLIzNN8wQ5OpeYEF81mEuUYF0CciA8=
|
|
||||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||||
golang.design/x/clipboard v0.7.0 h1:4Je8M/ys9AJumVnl8m+rZnIvstSnYj1fvzqYrU3TXvo=
|
|
||||||
golang.design/x/clipboard v0.7.0/go.mod h1:PQIvqYO9GP29yINEfsEn5zSQKAz3UgXmZKzDA6dnq2E=
|
|
||||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
|
||||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||||
golang.org/x/exp/shiny v0.0.0-20240506185415-9bf2ced13842 h1:kEvPiBVeT1JJGw/3THfe1W1zvTAvU1V6pCFV0icZvQs=
|
|
||||||
golang.org/x/exp/shiny v0.0.0-20240506185415-9bf2ced13842/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o=
|
|
||||||
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
|
|
||||||
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
|
||||||
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a h1:sYbmY3FwUWCBTodZL1S3JUuOvaW6kM2o+clDzzDNBWg=
|
|
||||||
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a/go.mod h1:Ede7gF0KGoHlj822RtphAHK1jLdrcuRBZg0sF1Q+SPc=
|
|
||||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
|
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
|
||||||
|
29
util/cli.go
29
util/cli.go
@ -7,40 +7,20 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
//"golang.design/x/clipboard"
|
"github.com/spf13/viper"
|
||||||
"github.com/atotto/clipboard"
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteToClipboard(val string) error {
|
func WriteToClipboard(val string) error {
|
||||||
clipboard.WriteAll(val)
|
cmd := exec.Command(viper.GetString("clipboard-command"), val)
|
||||||
return nil
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func WriteToClipboard(val string) error {
|
|
||||||
return WriteToClipboardWithTimeout(val, time.Second*5)
|
|
||||||
}
|
|
||||||
func WriteToClipboardWithTimeout(val string, timeout time.Duration) error {
|
|
||||||
ct := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
time.Sleep(timeout)
|
|
||||||
ct <- struct{}{}
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-clipboard.Write(clipboard.FmtText, []byte(val)):
|
|
||||||
fmt.Println("Clipboard Changed")
|
|
||||||
case <-ct:
|
|
||||||
fmt.Println("Clipboard Cleared")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func PromptUserForPassword(label string) (string, error) {
|
func PromptUserForPassword(label string) (string, error) {
|
||||||
fmt.Println(label)
|
fmt.Println(label)
|
||||||
bytePass, err := term.ReadPassword(int(syscall.Stdin))
|
bytePass, err := term.ReadPassword(int(syscall.Stdin))
|
||||||
@ -49,6 +29,7 @@ func PromptUserForPassword(label string) (string, error) {
|
|||||||
}
|
}
|
||||||
return string(bytePass), nil
|
return string(bytePass), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PromptUser(text string) string {
|
func PromptUser(text string) string {
|
||||||
var resp string
|
var resp string
|
||||||
fmt.Println(text)
|
fmt.Println(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user