From ef3ebf01353cbe2b587768056591ea8d122f5ae1 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Sat, 24 Aug 2019 21:08:38 +0200 Subject: [PATCH] allow custom history path --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index fd5f922..b814666 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var ( noPersist = app.Flag("no-persist", "Don't persist a copy buffer after a program exits").Short('P').Default("false").Bool() max = app.Flag("max-items", "items to store in history (with -d) or display before scrolling (with -s)").Default("15").Int() tool = app.Flag("selector", "Which selector to use: dmenu/rofi").Default("dmenu").String() + histpath = app.Flag("histpath", "Directory where to save history").Default("$XDG_DATA_HOME").String() ) func main() { @@ -38,11 +39,15 @@ func main() { os.Exit(1) } - h, err := os.UserHomeDir() - if err != nil { - log.Fatal(err) + histpath := *histpath + if histpath == "$XDG_DATA_HOME" { + home, err := os.UserHomeDir() + if err != nil { + log.Fatal(err) + } + histpath = path.Join(home, ".local/share/") } - histfile := path.Join(h, ".local/share/clipman.json") + histfile := path.Join(histpath, "clipman.json") var history []string b, err := ioutil.ReadFile(histfile)