From 12255a834190b101c032e923fbc2af6a6a882fb5 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Thu, 18 Apr 2019 16:15:35 +0200 Subject: [PATCH] fix(demon): don't abort on no selection --- demon.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/demon.go b/demon.go index 171649a..5852365 100644 --- a/demon.go +++ b/demon.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "log" "os/exec" "time" ) @@ -46,12 +47,18 @@ func filter(history []string, text string) []string { func listen(history []string, histfile string, persist bool, max int) error { for { - t, err := exec.Command("wl-paste", []string{"-n", "-t", "text"}...).Output() + t, err := exec.Command("wl-paste", []string{"-n", "-t", "text"}...).CombinedOutput() if err != nil { - return fmt.Errorf("error running wl-paste (demon.52): %s", err) + // wl-paste exits 1 if there's no selection (e.g., when running it at OS startup) + if string(t) != "No selection" { + log.Printf("Error running wl-paste (demon.52): %s", t) + } + time.Sleep(1 * time.Second) + continue } text := string(t) + if text == "" { // there's nothing to select, so we sleep. time.Sleep(1 * time.Second)