Skip to content

Commit

Permalink
feat(config): recognize komorebi_config_home for asc path
Browse files Browse the repository at this point in the history
This commit ensures that the KOMOREBI_CONFIG_HOME environment variable is recognized by the
komorebic check command and the static config loader when used to specify the location of the
applications.yaml file.

resolve #660
  • Loading branch information
LGUG2Z committed Feb 10, 2024
1 parent 5d812aa commit b64c0e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ pub fn resolve_home_path<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
resolved = true;
}

std::path::Component::Normal(c) if (c == "$Env:KOMOREBI_CONFIG_HOME") && !resolved => {
let komorebi_config_home =
PathBuf::from(std::env::var("KOMOREBI_CONFIG_HOME").ok().ok_or_else(|| {
anyhow!("there is no KOMOREBI_CONFIG_HOME environment variable set")
})?);

resolved_path.extend(komorebi_config_home.components());
resolved = true;
}

_ => resolved_path.push(c),
}
}
Expand Down
9 changes: 8 additions & 1 deletion komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ fn main() -> Result<()> {

if let Ok(config) = &parsed_config {
if let Some(asc_path) = config.get("app_specific_configuration_path") {
let normalized_asc_path = asc_path
let mut normalized_asc_path = asc_path
.to_string()
.replace(
"$Env:USERPROFILE",
Expand All @@ -1353,6 +1353,13 @@ fn main() -> Result<()> {
.replace('"', "")
.replace('\\', "/");

if let Ok(komorebi_config_home) = std::env::var("KOMOREBI_CONFIG_HOME") {
normalized_asc_path = normalized_asc_path
.replace("$Env:KOMOREBI_CONFIG_HOME", &komorebi_config_home)
.replace('"', "")
.replace('\\', "/");
}

if !Path::exists(Path::new(&normalized_asc_path)) {
println!("Application specific configuration file path '{normalized_asc_path}' does not exist. Try running 'komorebic fetch-asc'\n");
}
Expand Down

0 comments on commit b64c0e1

Please sign in to comment.