1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-15 19:15:24 +00:00

Prefer XDG vars if set - fixes #11

This commit is contained in:
makeworld 2020-06-22 11:56:55 -04:00
parent f0a75cf4a7
commit 199d122990
3 changed files with 18 additions and 4 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Desktop entry file
- Option to continue anyway when cert doesn't match TOFU database
- Display all `text/*` documents, not just gemini and plain (#12)
- Prefer XDG environment variables if they're set, to specify config dir, etc (#11)
### Changed
- Connection timeout is 15 seconds (was 5s)

View File

@ -67,7 +67,7 @@ Features in *italics* are in the master branch, but not in the latest release.
- [ ] History browser
## Configuration
The config file is written in the intuitive [TOML](https://github.com/toml-lang/toml) file format. See [default-config.toml](./default-config.toml) for details. By default this file is available at `~/.config/amfora/config.toml`.
The config file is written in the intuitive [TOML](https://github.com/toml-lang/toml) file format. See [default-config.toml](./default-config.toml) for details. By default this file is available at `~/.config/amfora/config.toml`, or `$XDG_CONFIG_HOME/amfora/config.toml`, if that variable is set.
On Windows, the file is in `%APPDATA%\amfora\config.toml`, which usually expands to `C:\Users\<username>\AppData\Roaming\amfora\config.toml`.

View File

@ -4,6 +4,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"github.com/makeworld-the-better-one/amfora/cache"
homedir "github.com/mitchellh/go-homedir"
@ -37,17 +38,29 @@ func Init() error {
configDir = amforaAppData
} else {
// Unix / POSIX system
configDir = filepath.Join(home, ".config", "amfora")
xdg_config, ok := os.LookupEnv("XDG_CONFIG_HOME")
if ok && strings.TrimSpace(xdg_config) != "" {
configDir = filepath.Join(xdg_config, "amfora")
} else {
// Default to ~/.config/amfora
configDir = filepath.Join(home, ".config", "amfora")
}
}
configPath = filepath.Join(configDir, "config.toml")
// Cache TOFU db directory and file paths
// Windows just stores it in APPDATA along with other stuff
if runtime.GOOS == "windows" {
// Windows just stores it in APPDATA along with other stuff
tofuDBDir = amforaAppData
} else {
// XDG cache dir on POSIX systems
tofuDBDir = filepath.Join(home, ".cache", "amfora")
xdg_cache, ok := os.LookupEnv("XDG_CACHE_HOME")
if ok && strings.TrimSpace(xdg_cache) != "" {
tofuDBDir = filepath.Join(xdg_cache, "amfora")
} else {
// Default to ~/.cache/amfora
tofuDBDir = filepath.Join(home, ".cache", "amfora")
}
}
tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml")