Skip to content
Permalink
Browse files

Add clipboard clearing after command xw, xu, xp

  • Loading branch information...
Raggaer committed Mar 1, 2019
1 parent cc8016e commit bed9cf7271a4f5110b32b9acae2ff631b7445d86
Showing with 26 additions and 8 deletions.
  1. +1 −1 README.md
  2. +3 −0 entry.go
  3. +22 −7 main.go
@@ -54,7 +54,7 @@ After deleting a backup of the database file is created (before the delete chang
## Clipboard

Commands like `xu` and `xp` copy the content to the system clipboard, making use of [github.com/atotto/clipboard](https://github.com/atotto/clipboard).
You will need `xclip` or `xsel` installed
You will need `xclip` or `xsel` installed. When copying content to the clipboard `gokpcli` will try to clear if after 10 seconds

`xsel` is the better approach, since it does not save a list of clipboard contents (and the command `xx` just sets an empty string as the clipboard content) so using `xsel` is the
more secure way of using the clipboard
@@ -292,6 +292,7 @@ func xp(args []string) {
e.Times.UsageCount++
clipboard.WriteAll(e.GetPassword())
fmt.Printf("Copied entry '%s' password to clipboard\r\n", e.GetTitle())
go clipboardClear(clipboardClearDuration, e.GetPassword())
}

// Command "xw" copies an entry URL
@@ -309,6 +310,7 @@ func xw(args []string) {
e.Times.UsageCount++
clipboard.WriteAll(e.GetContent("URL"))
fmt.Printf("Copied entry '%s' URL to clipboard\r\n", e.GetTitle())
go clipboardClear(clipboardClearDuration, e.GetContent("URL"))
}

// Command "xu" copies an entry username
@@ -326,6 +328,7 @@ func xu(args []string) {
e.Times.UsageCount++
clipboard.WriteAll(e.GetContent("UserName"))
fmt.Printf("Copied entry '%s' username to clipboard\r\n", e.GetTitle())
go clipboardClear(clipboardClearDuration, e.GetContent("UserName"))
}

func mask(data, m string) string {
29 main.go
@@ -9,18 +9,21 @@ import (
"os/signal"
"strings"
"syscall"
"time"

"github.com/atotto/clipboard"
"github.com/tobischo/gokeepasslib/v2"
)

var (
quit = make(chan struct{})
msg = make(chan string, 1)
waitCommandMessage = ">> gokpcli "
databaseLocation string
passwordFileLocation string
database *gokeepasslib.Database
doNotBackups = false
clipboardClearDuration = time.Second * 10
quit = make(chan struct{})
msg = make(chan string, 1)
waitCommandMessage = ">> gokpcli "
databaseLocation string
passwordFileLocation string
database *gokeepasslib.Database
doNotBackups = false
)

func main() {
@@ -117,3 +120,15 @@ func buildApplicationWaitMessage() string {
return str

}

// Clears the clipboard only if the content is equal to clipboard
func clipboardClear(at time.Duration, content string) {
time.Sleep(at)
clip, err := clipboard.ReadAll()
if err != nil {
return
}
if clip == content {
clipboard.WriteAll("")
}
}

0 comments on commit bed9cf7

Please sign in to comment.
You can’t perform that action at this time.