Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

expand user env vars

holby9c611210bfa0
diff --git a/packages/wm/src/containers/commands/exec_process.rs b/packages/wm/src/containers/commands/exec_process.rs
index cced356d..259fec66 100644
--- a/packages/wm/src/containers/commands/exec_process.rs
+++ b/packages/wm/src/containers/commands/exec_process.rs
@@ -1,9 +1,22 @@
use std::process::Command;
use std::env;
use anyhow::{Result, Context};
+use regex::Regex;
pub fn exec_process(process_name: &str, args: &[String]) -> Result<()> {
+ // Expand user profile environment variable
+ let user_profile = env::var("USERPROFILE")
+ .context("Failed to get environment variable for user profile directory")?;
+
+ let re = Regex::new(r"(?i)%userprofile%").unwrap();
+
+ let args: Vec<String> = args.iter().map(|arg| {
+ re.replace_all(arg, &user_profile).into_owned()
+ }).collect();
+
+ let process_name = re.replace_all(&process_name, &user_profile).into_owned();
+ // Start external process
let output = Command::new(process_name)
.args(args) // pass the args vector directly
.current_dir(env::var("USERPROFILE")