From c09deede85097b5a870b29e94b2be1bb0fa18450 Mon Sep 17 00:00:00 2001 From: Dhruv Thakur Date: Mon, 15 Jul 2024 01:16:48 +0200 Subject: [PATCH] fix: use correct data storage path on windows --- README.md | 6 +++--- cmd/root.go | 35 ++++++++++++++++------------------- internal/ui/help.go | 4 ++-- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index bb56462..37bf27d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ brew install dhth/tap/omm **go**: ```sh -go install github.com/dhth/omm@v0.2.0 +go install github.com/dhth/omm@v0.2.1 ``` Or get the binaries directly from a @@ -45,8 +45,8 @@ Or get the binaries directly from a 💡 Guide --- -omm offers guided walkthrough of its features, intended for new users of it. Run -it as follows. +omm offers a guided walkthrough of its features, intended for new users of it. +Run it as follows. ```bash omm guide diff --git a/cmd/root.go b/cmd/root.go index b38f82c..4d76cd9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,6 @@ import ( "fmt" "io/fs" "os" - "os/user" "path/filepath" "runtime" "strings" @@ -20,12 +19,13 @@ import ( ) const ( - author = "@dhth" - repoIssuesUrl = "https://github.com/dhth/omm/issues" - defaultDataDir = ".local/share" - dbFileName = "omm/omm.db" - printTasksDefault = 20 - taskListTitleMaxLen = 8 + author = "@dhth" + repoIssuesUrl = "https://github.com/dhth/omm/issues" + defaultDataDir = ".local/share" + defaultDataDirWindows = "AppData/Local" + dbFileName = "omm/omm.db" + printTasksDefault = 20 + taskListTitleMaxLen = 8 ) var ( @@ -286,8 +286,11 @@ Error: %s`, author, repoIssuesUrl, guideErr) }, } -func getUserHomeDir() string { - currentUser, err := user.Current() +func init() { + ros := runtime.GOOS + var defaultDBPath string + var dbPathAdditionalCxt string + hd, err := os.UserHomeDir() if err != nil { die(`Couldn't get your home directory. This is a fatal error; @@ -297,25 +300,19 @@ Let %s know about this via %s. Error: %s`, author, repoIssuesUrl, err) } - return currentUser.HomeDir -} - -func init() { - ros := runtime.GOOS - var defaultDBPath string - var dbPathAdditionalCxt string - switch ros { case "linux": xdgDataHome := os.Getenv("XDG_DATA_HOME") if xdgDataHome != "" { defaultDBPath = filepath.Join(xdgDataHome, dbFileName) } else { - defaultDBPath = filepath.Join(getUserHomeDir(), defaultDataDir, dbFileName) + defaultDBPath = filepath.Join(hd, defaultDataDir, dbFileName) } dbPathAdditionalCxt = "; will use $XDG_DATA_HOME by default, if set" + case "windows": + defaultDBPath = filepath.Join(hd, defaultDataDirWindows, dbFileName) default: - defaultDBPath = filepath.Join(getUserHomeDir(), defaultDataDir, dbFileName) + defaultDBPath = filepath.Join(hd, defaultDataDir, dbFileName) } rootCmd.Flags().StringVarP(&dbPath, "db-path", "d", defaultDBPath, fmt.Sprintf("location of omm's database file%s", dbPathAdditionalCxt)) diff --git a/internal/ui/help.go b/internal/ui/help.go index ae8bbcc..4a0e45e 100644 --- a/internal/ui/help.go +++ b/internal/ui/help.go @@ -2,6 +2,8 @@ package ui var helpStr = `omm ("on-my-mind") is a keyboard-driven task manager for the command line. +Tip: Run "omm guide" for a guided walkthrough of omm's features. + [Keymaps] j/↓ move cursor down k/↑ move cursor up @@ -25,6 +27,4 @@ d show task details in a full screen pane v toggle between compact and spacious view h/l move backwards/forwards when in the task details view q/esc/ctrl+c go back/quit - -Run "omm guide" for a guided walkthrough of omm's features. `