Skip to content

Commit

Permalink
Extract final part of the appdir into a global variable for potential (
Browse files Browse the repository at this point in the history
…gopasspw#1978)

re-use

RELEASE_NOTES=n/a

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Aug 18, 2021
1 parent 96a515b commit f4820bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions pkg/appdir/appdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/gopasspw/gopass/pkg/debug"
)

var (
// Name is used in the final path of the generated path
Name = "gopass"
)

// UserHome returns the users home dir
func UserHome() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
Expand Down
12 changes: 6 additions & 6 deletions pkg/appdir/appdir_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import (
// UserConfig returns the users config dir
func UserConfig() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".config", "gopass")
return filepath.Join(hd, ".config", Name)
}

return filepath.Join(os.Getenv("APPDATA"), "gopass")
return filepath.Join(os.Getenv("APPDATA"), Name)
}

// UserCache returns the users cache dir
func UserCache() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".cache", "gopass")
return filepath.Join(hd, ".cache", Name)
}

return filepath.Join(os.Getenv("LOCALAPPDATA"), "gopass")
return filepath.Join(os.Getenv("LOCALAPPDATA"), Name)
}

// UserData returns the users data dir
func UserData() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".local", "share", "gopass")
return filepath.Join(hd, ".local", "share", Name)
}
return filepath.Join(os.Getenv("LOCALAPPDATA"), "gopass")
return filepath.Join(os.Getenv("LOCALAPPDATA"), Name)
}
12 changes: 6 additions & 6 deletions pkg/appdir/appdir_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ import (
// UserConfig returns the users config dir
func UserConfig() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".config", "gopass")
return filepath.Join(hd, ".config", Name)
}

base := os.Getenv("XDG_CONFIG_HOME")
if base == "" {
base = filepath.Join(os.Getenv("HOME"), ".config")
}

return filepath.Join(base, "gopass")
return filepath.Join(base, Name)
}

// UserCache returns the users cache dir
func UserCache() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".cache", "gopass")
return filepath.Join(hd, ".cache", Name)
}

base := os.Getenv("XDG_CACHE_HOME")
if base == "" {
base = filepath.Join(os.Getenv("HOME"), ".cache")
}

return filepath.Join(base, "gopass")
return filepath.Join(base, Name)
}

// UserData returns the users data dir
func UserData() string {
if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
return filepath.Join(hd, ".local", "share", "gopass")
return filepath.Join(hd, ".local", "share", Name)
}

base := os.Getenv("XDG_DATA_HOME")
if base == "" {
base = filepath.Join(os.Getenv("HOME"), ".local", "share")
}

return filepath.Join(base, "gopass")
return filepath.Join(base, Name)
}

0 comments on commit f4820bb

Please sign in to comment.