From 8742f901b80d5908ac16706e30d5fe991b7610b6 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Mon, 25 Mar 2019 19:13:19 +0100 Subject: [PATCH] small cosmetics fixes --- demon.go | 3 --- main.go | 8 ++------ selector.go | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/demon.go b/demon.go index 2795825..7709d45 100644 --- a/demon.go +++ b/demon.go @@ -43,7 +43,6 @@ 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() @@ -72,7 +71,6 @@ func listen(history []string, histfile string, persist bool, max int) error { } // remove duplicates - // consider doing this in the frontend, for sparing resources history = filter(history, text) } @@ -98,5 +96,4 @@ func listen(history []string, histfile string, persist bool, max int) error { // also because if we copied once, we might copy soon after. time.Sleep(250 * time.Millisecond) } - } diff --git a/main.go b/main.go index 85544e2..31b8ac1 100644 --- a/main.go +++ b/main.go @@ -18,11 +18,6 @@ var ( max = app.Flag("max-items", "items to store in history (with -d) or display before scrolling (with -s)").Default("15").Int() ) -var ( - histfile string - history []string -) - func main() { app.HelpFlag.Short('h') kingpin.MustParse(app.Parse(os.Args[1:])) @@ -34,8 +29,9 @@ func main() { if err != nil { log.Fatal(err) } - histfile = path.Join(h, ".local/share/clipman.json") + histfile := path.Join(h, ".local/share/clipman.json") + var history []string b, err := ioutil.ReadFile(histfile) if err == nil { if err := json.Unmarshal(b, &history); err != nil { diff --git a/selector.go b/selector.go index b4afabd..524494b 100644 --- a/selector.go +++ b/selector.go @@ -8,7 +8,6 @@ import ( ) func selector(history []string, max int) error { - // reverse the history for i, j := 0, len(history)-1; i < j; i, j = i+1, j-1 { history[i], history[j] = history[j], history[i] @@ -20,6 +19,7 @@ func selector(history []string, max int) error { return nil } + // serve selection to the OS if err := exec.Command("wl-copy", selected).Run(); err != nil { return err }