fix: stop leaking content of clipboard
This commit is contained in:
parent
9097bb4f6b
commit
bb094dab9e
3 changed files with 23 additions and 6 deletions
|
@ -6,6 +6,10 @@
|
|||
- `--tool-args` argument to pass additional args to dmenu/rofi/etc.
|
||||
- rofi and wofi now display a prompt hint to remind you whether you are picking or clearing
|
||||
|
||||
**Notable Bug fixes**
|
||||
|
||||
- we don't leak our clipboard to `ps` anymore
|
||||
|
||||
# 1.1
|
||||
|
||||
**New features**
|
||||
|
|
20
main.go
20
main.go
|
@ -73,7 +73,7 @@ func main() {
|
|||
|
||||
if selection != "" {
|
||||
// serve selection to the OS
|
||||
if err := exec.Command("wl-copy", "--", selection).Run(); err != nil {
|
||||
if err := serveTxt(selection); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if err := exec.Command("wl-copy", "--", history[len(history)-1]).Run(); err != nil {
|
||||
if err := serveTxt(history[len(history)-1]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
case "clear":
|
||||
|
@ -116,7 +116,7 @@ func main() {
|
|||
if selection == history[len(history)-1] {
|
||||
// wl-copy is still serving the copy, so replace with next latest
|
||||
// note: we alread exited if less than 2 items
|
||||
if err := exec.Command("wl-copy", "--", history[len(history)-2]).Run(); err != nil {
|
||||
if err := serveTxt(history[len(history)-2]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -166,3 +166,17 @@ func getHistory(rawPath string) (string, []string, error) {
|
|||
|
||||
return histfile, history, nil
|
||||
}
|
||||
|
||||
func serveTxt(s string) error {
|
||||
bin, err := exec.LookPath("wl-copy")
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't find wl-copy: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Cmd{Path: bin, Stdin: strings.NewReader(s)}
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("Error running wl-copy: %s", err) // don't abort, minor error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func store(text string, history []string, histfile string, max int, persist bool) error {
|
||||
|
@ -43,8 +42,8 @@ func store(text string, history []string, histfile string, max int, persist bool
|
|||
// make the copy buffer available to all applications,
|
||||
// even when the source has disappeared
|
||||
if persist {
|
||||
if err := exec.Command("wl-copy", []string{"--", text}...).Run(); err != nil {
|
||||
log.Printf("Error running wl-copy: %s", err) // don't abort, minor error
|
||||
if err := serveTxt(text); err != nil {
|
||||
log.Print(err) // don't abort, minor error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue