Skip to content

Commit

Permalink
fix: case when no XDG_{CACHE,CONFIG}_HOME
Browse files Browse the repository at this point in the history
fixes #118
  • Loading branch information
sentriz committed Oct 15, 2024
1 parent e9ac303 commit b3d4bd4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cliphist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3d4bd4

Please sign in to comment.