From 6c5922d5f0b2d9d7b6e4c39593c6892a65f74e54 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 28 Oct 2024 20:08:09 +0100 Subject: config: refactor, accept more possible config dirs I'm starting to favor dotfiles over XDG basedirs, but there's no reason why we couldn't have both. So now the search path is: 0. if config was set through -C, use that 1. $CHA_CONFIG_DIR is set -> $CHA_CONFIG_DIR/config.toml 2. $XDG_CONFIG_HOME is set -> $XDG_CONFIG_HOME/chawan/config.toml 3. ~/.config/chawan/config.toml exists -> use that 4. ~/.chawan/config.toml exists -> use that Notably, this makes it so the default directory is ~/.chawan *if* you don't have an existing config.toml file. So in that case known_hosts will be placed in ~/.chawan/known_hosts. However, configurations with a config in ~/.config/chawan/config.toml continue to work as expected, as for those the known_hosts file remains inside ~/.config/chawan/. Finally, I've added a default user CGI directory to reduce friction in setting CGI up. (Like known_hosts, it's also relative to whatever config dir you have.) --- src/utils/twtstr.nim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/utils') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 1f43c443..99e5f6ee 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -717,3 +717,9 @@ func btoa*(data: openArray[uint8]): string = func btoa*(data: openArray[char]): string = return btoa(data.toOpenArrayByte(0, data.len - 1)) + +proc getEnvEmpty*(name: string; fallback = ""): string = + let res = getEnv(name, fallback) + if res != "": + return res + return fallback -- cgit