mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-08-17 18:50:25 +03:00
XDG config (#100)
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
This commit is contained in:
parent
efc10a2b3e
commit
270dddfbc2
@ -13,6 +13,8 @@ import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/makeworld-the-better-one/amfora/cache"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/rkoesters/xdg/basedir"
|
||||
"github.com/rkoesters/xdg/userdirs"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.com/tslocum/cview"
|
||||
)
|
||||
@ -60,12 +62,11 @@ func Init() error {
|
||||
configDir = amforaAppData
|
||||
} else {
|
||||
// Unix / POSIX system
|
||||
xdg_config, ok := os.LookupEnv("XDG_CONFIG_HOME")
|
||||
if ok && strings.TrimSpace(xdg_config) != "" {
|
||||
configDir = filepath.Join(xdg_config, "amfora")
|
||||
} else {
|
||||
if basedir.ConfigHome == "" {
|
||||
// Default to ~/.config/amfora
|
||||
configDir = filepath.Join(home, ".config", "amfora")
|
||||
} else {
|
||||
configDir = filepath.Join(basedir.ConfigHome, "amfora")
|
||||
}
|
||||
}
|
||||
configPath = filepath.Join(configDir, "config.toml")
|
||||
@ -83,12 +84,11 @@ func Init() error {
|
||||
tofuDBDir = amforaAppData
|
||||
} else {
|
||||
// XDG cache dir on POSIX systems
|
||||
xdg_cache, ok := os.LookupEnv("XDG_CACHE_HOME")
|
||||
if ok && strings.TrimSpace(xdg_cache) != "" {
|
||||
tofuDBDir = filepath.Join(xdg_cache, "amfora")
|
||||
} else {
|
||||
if basedir.CacheHome == "" {
|
||||
// Default to ~/.cache/amfora
|
||||
tofuDBDir = filepath.Join(home, ".cache", "amfora")
|
||||
} else {
|
||||
tofuDBDir = filepath.Join(basedir.CacheHome, "amfora")
|
||||
}
|
||||
}
|
||||
tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml")
|
||||
@ -99,12 +99,11 @@ func Init() error {
|
||||
bkmkDir = amforaAppData
|
||||
} else {
|
||||
// XDG data dir on POSIX systems
|
||||
xdg_data, ok := os.LookupEnv("XDG_DATA_HOME")
|
||||
if ok && strings.TrimSpace(xdg_data) != "" {
|
||||
bkmkDir = filepath.Join(xdg_data, "amfora")
|
||||
} else {
|
||||
if basedir.DataHome == "" {
|
||||
// Default to ~/.local/share/amfora
|
||||
bkmkDir = filepath.Join(home, ".local", "share", "amfora")
|
||||
} else {
|
||||
bkmkDir = filepath.Join(basedir.DataHome, "amfora")
|
||||
}
|
||||
}
|
||||
bkmkPath = filepath.Join(bkmkDir, "bookmarks.toml")
|
||||
@ -151,7 +150,11 @@ func Init() error {
|
||||
if viper.GetString("a-general.downloads") == "" {
|
||||
// Find default Downloads dir
|
||||
// This seems to work for all OSes?
|
||||
DownloadsDir = filepath.Join(home, "Downloads")
|
||||
if userdirs.Download == "" {
|
||||
DownloadsDir = filepath.Join(home, "Downloads")
|
||||
} else {
|
||||
DownloadsDir = userdirs.Download
|
||||
}
|
||||
// Create it just in case
|
||||
err = os.MkdirAll(DownloadsDir, 0755)
|
||||
if err != nil {
|
||||
|
1
go.mod
1
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mitchellh/mapstructure v1.3.1 // indirect
|
||||
github.com/pelletier/go-toml v1.8.0 // indirect
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b
|
||||
github.com/spf13/afero v1.2.2 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -177,6 +177,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b h1:8NiY6v9/IlFU8osj1L7kqzRbrG6e3izRQQjGze1Q1R0=
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b/go.mod h1:T1HolqzmdHnJIH6p7A9LDuvYGQgEHx9ijX3vKgDKU60=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
|
Loading…
Reference in New Issue
Block a user