Skip to content

Commit

Permalink
config: use XDG base directory (#14)
Browse files Browse the repository at this point in the history
* config: use XDG base directory

* config: update default config file

* clear white space

Signed-off-by: Avelino <[email protected]>

* move configuration file into `.config` root

Signed-off-by: Avelino <[email protected]>

* describe why we use XDG pattern

Signed-off-by: Avelino <[email protected]>

---------

Signed-off-by: Avelino <[email protected]>
  • Loading branch information
avelino authored Mar 26, 2023
1 parent 5097ec5 commit 7ce716a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ Rio also relies on Rust memory behavior: Rust is a memory-safe language that emp

The configuration should be the following paths otherwise Rio will use the default configuration.

- macOs path: `~/.rio/config.toml`
- macOS path: `~/.config/rio.toml`

Default configuration of `config.toml`:
> `$XDG_CONFIG_HOME` defines the base directory relative to which user specific configuration files should be stored. If `$XDG_CONFIG_HOME` is either not set or empty, a default equal to `$HOME/.config` should be used.
Default configuration of `rio.toml`:

```toml
# Rio default configuration file
Expand Down
7 changes: 4 additions & 3 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ impl Config {
}

pub fn load_macos() -> Self {
let base_dir_buffer = dirs::home_dir().unwrap();
// XDG base directory
let base_dir_buffer = dirs::config_dir().unwrap();
let base_dir = base_dir_buffer.to_str().unwrap();

let path = format!("{base_dir}/.rio/config.toml");
let path = format!("{base_dir}/rio.toml");
if std::path::Path::new(&path).exists() {
let content = std::fs::read_to_string(path).unwrap();
match toml::from_str(&content) {
Expand Down Expand Up @@ -504,7 +505,7 @@ mod tests {
[advanced]
monochrome = true
enable-fps-counter = true
tab-character = '▲'
tab-character = '▲'
"#,
);

Expand Down

0 comments on commit 7ce716a

Please sign in to comment.