mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-09-17 07:11:22 +02:00
feat(core): use PathExt to unify env var resolution
This new implementation allows for expanding any environment variable so it is not limited to just `~`, `$HOME`, `$Env:USERPROFILE` and `$Env:KOMOREBI_CONFIG_HOME`. It expands the follwing formats: - CMD: `%variable%` - PowerShell: `$Env:variable` - Bash: `$variable` I searched throughout the code base for path and migrate any code that might need to PathExt::replace_env. It is possible that I might have missed a few places due to my unfamiliarity with the code base, so if you find any, please let me know. Most of the paths that needed this trait, are in: - Clap arguments, and that was handled by #[value_parse] attribute and a helper function. - SocketMessage and that was handled by custom deserialization with the help of serde_with crate
This commit is contained in:
+10
-6
@@ -49,6 +49,7 @@ use komorebi_client::Colour;
|
||||
use komorebi_client::KomorebiTheme;
|
||||
use komorebi_client::MonitorNotification;
|
||||
use komorebi_client::NotificationEvent;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_themes::catppuccin_egui;
|
||||
use komorebi_themes::Base16Value;
|
||||
@@ -500,13 +501,16 @@ impl Komobar {
|
||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| dirs::home_dir().expect("there is no home directory"),
|
||||
|home_path| {
|
||||
let home = PathBuf::from(&home_path);
|
||||
let home = home_path.replace_env();
|
||||
|
||||
assert!(
|
||||
home.is_dir(),
|
||||
"$Env:KOMOREBI_CONFIG_HOME is set to '{}', which is not a valid directory",
|
||||
home_path
|
||||
);
|
||||
|
||||
home
|
||||
|
||||
if home.as_path().is_dir() {
|
||||
home
|
||||
} else {
|
||||
panic!("$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user