diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 7521b3b0..24c1db04 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -800,6 +800,22 @@ struct Stop { masir: bool, } +#[derive(Parser)] +struct Kill { + /// Kill whkd if it is running as a background process + #[clap(long)] + whkd: bool, + /// Kill ahk if it is running as a background process + #[clap(long)] + ahk: bool, + /// Kill komorebi-bar if it is running as a background process + #[clap(long)] + bar: bool, + /// Kill masir if it is running as a background process + #[clap(long)] + masir: bool, +} + #[derive(Parser)] struct SaveResize { /// File to which the resize layout dimensions should be saved @@ -922,6 +938,8 @@ enum SubCommand { Start(Start), /// Stop the komorebi.exe process and restore all hidden windows Stop(Stop), + /// Kill background processes started by komorebic + Kill(Kill), /// Check komorebi configuration and related files for common errors Check, /// Show the path to komorebi.json @@ -2305,6 +2323,78 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue } } } + SubCommand::Kill(arg) => { + if arg.whkd { + let script = r" +Stop-Process -Name:whkd -ErrorAction SilentlyContinue + "; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + + if arg.bar { + let script = r" +Stop-Process -Name:komorebi-bar -ErrorAction SilentlyContinue + "; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + + if arg.masir { + let script = r" +Stop-Process -Name:masir -ErrorAction SilentlyContinue + "; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + + if arg.ahk { + let script = r#" +if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { + (Get-CimInstance Win32_Process | Where-Object { + ($_.CommandLine -like '*komorebi.ahk"') -and + ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe', 'AutoHotkeyUX.exe')) + } | Select-Object -First 1) | ForEach-Object { + Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue + } +} else { + (Get-WmiObject Win32_Process | Where-Object { + ($_.CommandLine -like '*komorebi.ahk"') -and + ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe', 'AutoHotkeyUX.exe')) + } | Select-Object -First 1) | ForEach-Object { + Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue + } +} +"#; + + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + } SubCommand::IgnoreRule(arg) => { send_message(&SocketMessage::IgnoreRule(arg.identifier, arg.id))?; }