summaryrefslogtreecommitdiff
path: root/src/global.cc
diff options
context:
space:
mode:
authorCédric Barreteau <unknown>2020-08-22 15:38:41 +0200
committerJohn Wiegley <johnw@newartisans.com>2020-08-28 11:05:34 -0700
commitc79674649dee7577d6061e3d0776922257520fd0 (patch)
tree305e466debaeb36e3ea49a37e952498602eb88e4 /src/global.cc
parent718ba0e3139d365ffb7883cb2c937cfe23656506 (diff)
downloadfork-ledger-c79674649dee7577d6061e3d0776922257520fd0.tar.gz
fork-ledger-c79674649dee7577d6061e3d0776922257520fd0.tar.bz2
fork-ledger-c79674649dee7577d6061e3d0776922257520fd0.zip
Add support for `$XDG_CONFIG_HOME`
`$XDG_CONFIG_HOME/ledger/ledgerrc` and `$HOME/.config/ledger/ledgerrc` are tried first when looking for an init file.
Diffstat (limited to 'src/global.cc')
-rw-r--r--src/global.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/global.cc b/src/global.cc
index 32d3cc5a..5a5df6f5 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -136,17 +136,28 @@ void global_scope_t::read_init()
path init_file;
if (HANDLED(init_file_)) {
init_file=HANDLER(init_file_).str();
- if (!exists(init_file)) {
+ if (! exists(init_file)) {
throw_(parse_error, _f("Could not find specified init file %1%") % init_file);
}
} else {
- if (const char * home_var = std::getenv("HOME")) {
- init_file = (path(home_var) / ".ledgerrc");
+ // in order, try to read the init file from:
+ // - $XDG_CONFIG_HOME/ledger/ledgerrc
+ // - $HOME/.config/ledger/ledgerrc
+ // - $HOME/.ledgerrc
+ // - ./.ledgerrc
+ if (const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME")) {
+ init_file = (path(xdg_config_home) / "ledger" / "ledgerrc");
+ }
+ if (! exists(init_file)) {
+ if (const char * home_var = std::getenv("HOME")) {
+ init_file = (path(home_var) / ".config" / "ledger" / "ledgerrc");
+ if (! exists(init_file)) {
+ init_file = (path(home_var) / ".ledgerrc");
+ }
+ }
if (! exists(init_file)) {
init_file = ("./.ledgerrc");
}
- } else {
- init_file = ("./.ledgerrc");
}
}
if (exists(init_file)) {