From b3d4bd49e801a0b3438074911909dadace7ee0fb Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 16 Oct 2024 00:41:50 +0100 Subject: [PATCH] fix: case when no XDG_{CACHE,CONFIG}_HOME fixes #118 --- cliphist.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cliphist.go b/cliphist.go index 4be595d..8d4d6c0 100644 --- a/cliphist.go +++ b/cliphist.go @@ -41,19 +41,27 @@ func main() { }) } + cacheHome, err := os.UserCacheDir() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + configHome, err := os.UserConfigDir() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + maxItems := flag.Uint64("max-items", 750, "maximum number of items to store") maxDedupeSearch := flag.Uint64("max-dedupe-search", 100, "maximum number of last items to look through when finding duplicates") previewWidth := flag.Uint("preview-width", 100, "maximum number of characters to preview") - dbPath := flag.String("db-path", "$XDG_CACHE_HOME/cliphist/db", "path to db") - configPath := flag.String("config-path", "$XDG_CONFIG_HOME/cliphist/config", "overwrite config path to use instead of cli flags") + dbPath := flag.String("db-path", filepath.Join(cacheHome, "cliphist", "db"), "path to db") + configPath := flag.String("config-path", filepath.Join(configHome, "cliphist", "config"), "overwrite config path to use instead of cli flags") flag.Parse() flagconf.ParseEnv() flagconf.ParseConfig(*configPath) - *dbPath = os.ExpandEnv(*dbPath) - - var err error switch flag.Arg(0) { case "store": switch os.Getenv("CLIPBOARD_STATE") { // from man wl-clipboard