Skip to content

Commit

Permalink
fix: use correct data storage path on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 14, 2024
1 parent 7b9c7b4 commit c09deed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
35 changes: 16 additions & 19 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io/fs"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
Expand All @@ -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 (
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
`

0 comments on commit c09deed

Please sign in to comment.