mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-25 02:41:13 +01:00
feat(cli): add ahk flag to static config start cmd
This commit introduces a new --ahk flag to the start command, which works similarly to the --whkd, and attempts to load an ahk key binding configuration script on startup. The attempt is made from within the komorebic process, rather than the komorebi process. resolve #529
This commit is contained in:
@@ -607,6 +607,7 @@ struct ActiveWindowBorderOffset {
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
struct Start {
|
||||
/// Allow the use of komorebi's custom focus-follows-mouse implementation
|
||||
#[clap(action, short, long = "ffm")]
|
||||
@@ -623,6 +624,9 @@ struct Start {
|
||||
/// Start whkd in a background process
|
||||
#[clap(action, long)]
|
||||
whkd: bool,
|
||||
/// Start autohotkey configuration file
|
||||
#[clap(action, long)]
|
||||
ahk: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
@@ -1398,10 +1402,22 @@ fn main() -> Result<()> {
|
||||
)?;
|
||||
}
|
||||
SubCommand::Start(arg) => {
|
||||
let mut ahk: String = String::from("autohotkey.exe");
|
||||
|
||||
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") {
|
||||
if which(&komorebi_ahk_exe).is_ok() {
|
||||
ahk = komorebi_ahk_exe;
|
||||
}
|
||||
}
|
||||
|
||||
if arg.whkd && which("whkd").is_err() {
|
||||
return Err(anyhow!("could not find whkd, please make sure it is installed before using the --whkd flag"));
|
||||
}
|
||||
|
||||
if arg.ahk && which(&ahk).is_err() {
|
||||
return Err(anyhow!("could not find autohotkey, please make sure it is installed before using the --ahk flag"));
|
||||
}
|
||||
|
||||
let mut buf: PathBuf;
|
||||
|
||||
// The komorebi.ps1 shim will only exist in the Path if installed by Scoop
|
||||
@@ -1502,6 +1518,28 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if arg.ahk {
|
||||
let home = HOME_DIR.clone();
|
||||
let mut config_ahk = home;
|
||||
config_ahk.push("komorebi.ahk");
|
||||
|
||||
let script = format!(
|
||||
r#"
|
||||
Start-Process {ahk} {config} -WindowStyle hidden
|
||||
"#,
|
||||
config = config_ahk.as_os_str().to_string_lossy()
|
||||
);
|
||||
|
||||
match powershell_script::run(&script) {
|
||||
Ok(_) => {
|
||||
println!("{script}");
|
||||
}
|
||||
Err(error) => {
|
||||
println!("Error: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SubCommand::Stop(arg) => {
|
||||
if arg.whkd {
|
||||
|
||||
Reference in New Issue
Block a user