fix: don't fail on missing wl-copy

This commit is contained in:
yory8 2019-10-27 23:18:46 +01:00
parent bb094dab9e
commit 545642bd2b
2 changed files with 6 additions and 15 deletions

16
main.go
View file

@ -73,9 +73,7 @@ func main() {
if selection != "" { if selection != "" {
// serve selection to the OS // serve selection to the OS
if err := serveTxt(selection); err != nil { serveTxt(selection)
log.Fatal(err)
}
} }
case "restore": case "restore":
if len(history) == 0 { if len(history) == 0 {
@ -83,9 +81,7 @@ func main() {
return return
} }
if err := serveTxt(history[len(history)-1]); err != nil { serveTxt(history[len(history)-1])
log.Fatal(err)
}
case "clear": case "clear":
// remove all history // remove all history
if *clearAll { if *clearAll {
@ -167,16 +163,14 @@ func getHistory(rawPath string) (string, []string, error) {
return histfile, history, nil return histfile, history, nil
} }
func serveTxt(s string) error { func serveTxt(s string) {
bin, err := exec.LookPath("wl-copy") bin, err := exec.LookPath("wl-copy")
if err != nil { if err != nil {
return fmt.Errorf("couldn't find wl-copy: %v", err) log.Printf("couldn't find wl-copy: %v\n", err)
} }
cmd := exec.Cmd{Path: bin, Stdin: strings.NewReader(s)} cmd := exec.Cmd{Path: bin, Stdin: strings.NewReader(s)}
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Printf("Error running wl-copy: %s", err) // don't abort, minor error log.Printf("error running wl-copy: %s\n", err)
} }
return nil
} }

View file

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
) )
func store(text string, history []string, histfile string, max int, persist bool) error { func store(text string, history []string, histfile string, max int, persist bool) error {
@ -42,9 +41,7 @@ func store(text string, history []string, histfile string, max int, persist bool
// make the copy buffer available to all applications, // make the copy buffer available to all applications,
// even when the source has disappeared // even when the source has disappeared
if persist { if persist {
if err := serveTxt(text); err != nil { serveTxt(text)
log.Print(err) // don't abort, minor error
}
} }
return nil return nil