Skip to content

Commit

Permalink
Reapply pull request #7
Browse files Browse the repository at this point in the history
It was overwritten accidentally, when merging `complete_refactor` to
`dev`
  • Loading branch information
andreykaere committed Dec 2, 2023
1 parent 20d5536 commit 0133efe
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,36 @@ pub fn load_bspwm(config_file: Option<&Path>) -> BspwmConfig {
}

fn locate_config_file() -> Option<PathBuf> {
if let Ok(default_dir) = env::var("XDG_CONFIG_HOME") {
let default_config = format!("{default_dir}/ixwindow/ixwindow.toml");

if Path::new(&default_config).exists() {
return Some(PathBuf::from(default_config));
}
}

if let Ok(specified_config) = env::var("IXWINDOW_CONFIG_PATH") {
if Path::new(&specified_config).exists() {
return Some(PathBuf::from(specified_config));
}
}

let default_dir = match env::var("XDG_CONFIG_HOME") {
Err(_) => format!(
"{}/.config",
env::var("HOME").expect(
"$HOME is not set, but is needed \
because $XDG_CONFIG_HOME is not set"
)
),
Ok(path) if path.is_empty() => format!(
"{}/.config",
env::var("HOME").expect(
"$HOME is not set, but is needed \
because $XDG_CONFIG_HOME is empty"
)
),
Ok(path) => path,
};

let default_config = format!("{default_dir}/ixwindow/ixwindow.toml");

if Path::new(&default_config).exists() {
return Some(default_config);
}

None
}

Expand Down

0 comments on commit 0133efe

Please sign in to comment.