fall back to $HOME/.config and $HOME/.local/share

This commit is contained in:
Emma Tebibyte 2023-04-15 16:25:20 -04:00
parent a3ba320016
commit 70f242f8f6
1 changed files with 16 additions and 4 deletions

View File

@ -48,16 +48,28 @@ impl Default for Config {
pub fn get_config_dir() -> PathBuf {
std::env::var_os("XDG_CONFIG_HOME")
.map(PathBuf::try_from)
.expect("$XDG_CONFIG_HOME is unset")
.unwrap()
.expect("$XDG_CONFIG_HOME is unset.")
.unwrap_or_else(|_| {
std::env::var_os("HOME")
.map(PathBuf::try_from)
.expect("User has no $HOME.")
.unwrap()
.join(".config")
})
.join("breed")
}
pub fn get_data_dir() -> PathBuf {
std::env::var_os("XDG_DATA_HOME")
.map(PathBuf::try_from)
.expect("$XDG_DATA_HOME is unset")
.unwrap()
.expect("$XDG_DATA_HOME is unset.")
.unwrap_or_else(|_| {
std::env::var_os("HOME")
.map(PathBuf::try_from)
.expect("User has no $HOME.")
.unwrap()
.join(".local/share")
})
.join("breed")
}