mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 10:08:33 +02: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)]
|
#[derive(Parser, AhkFunction)]
|
||||||
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
struct Start {
|
struct Start {
|
||||||
/// Allow the use of komorebi's custom focus-follows-mouse implementation
|
/// Allow the use of komorebi's custom focus-follows-mouse implementation
|
||||||
#[clap(action, short, long = "ffm")]
|
#[clap(action, short, long = "ffm")]
|
||||||
@@ -623,6 +624,9 @@ struct Start {
|
|||||||
/// Start whkd in a background process
|
/// Start whkd in a background process
|
||||||
#[clap(action, long)]
|
#[clap(action, long)]
|
||||||
whkd: bool,
|
whkd: bool,
|
||||||
|
/// Start autohotkey configuration file
|
||||||
|
#[clap(action, long)]
|
||||||
|
ahk: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, AhkFunction)]
|
#[derive(Parser, AhkFunction)]
|
||||||
@@ -1398,10 +1402,22 @@ fn main() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
SubCommand::Start(arg) => {
|
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() {
|
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"));
|
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;
|
let mut buf: PathBuf;
|
||||||
|
|
||||||
// The komorebi.ps1 shim will only exist in the Path if installed by Scoop
|
// 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) => {
|
SubCommand::Stop(arg) => {
|
||||||
if arg.whkd {
|
if arg.whkd {
|
||||||
|
|||||||
Reference in New Issue
Block a user