feat(config): add pwsh cfgen + ps1 file watcher

This commit adds a command to generate application-specific
configuration in the format of a PowerShell ps1 file, as well as the
ability to automatically launch a komorebi.ps1 configuration file on
startup.

If a komorebi.ps1 file is found and launched at startup, the
watch-configuration command will watch and hot reload this file when any
changes are made.

A sample komorebi.ps1 file has been added to the root of the repository,
along with a sample whkdrc file, showing how the two can be used
together to replace AHK.

re #339
This commit is contained in:
LGUG2Z
2023-01-20 17:02:43 -08:00
committed by جاد
parent b89e5eafd2
commit afde7a3fb5
9 changed files with 696 additions and 31 deletions

View File

@@ -25,6 +25,7 @@ install:
komorebic ahk-library
cat '%USERPROFILE%\.config\komorebi\komorebic.lib.ahk' > komorebic.lib.ahk
cat '%USERPROFILE%\.config\komorebi\komorebi.generated.ahk' > komorebi.generated.ahk
cat '%USERPROFILE%\.config\komorebi\komorebi.generated.ps1' > komorebi.generated.ps1
run:
just install-komorebic

View File

@@ -20,39 +20,44 @@ pub enum ApplicationOptions {
}
impl ApplicationOptions {
#[must_use]
pub fn raw_cfgen(&self, kind: &ApplicationIdentifier, id: &str) -> String {
match self {
ApplicationOptions::ObjectNameChange => {
format!(
"komorebic.exe identify-object-name-change-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::Layered => {
format!(
"komorebic.exe identify-layered-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::BorderOverflow => {
format!(
"komorebic.exe identify-border-overflow-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::TrayAndMultiWindow => {
format!(
"komorebic.exe identify-tray-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::Force => {
format!("komorebic.exe manage-rule {} \"{}\"", kind, id)
}
}
}
#[must_use]
pub fn cfgen(&self, kind: &ApplicationIdentifier, id: &str) -> String {
format!(
"Run, {}, , Hide",
match self {
ApplicationOptions::ObjectNameChange => {
format!(
"komorebic.exe identify-object-name-change-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::Layered => {
format!(
"komorebic.exe identify-layered-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::BorderOverflow => {
format!(
"komorebic.exe identify-border-overflow-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::TrayAndMultiWindow => {
format!(
"komorebic.exe identify-tray-application {} \"{}\"",
kind, id
)
}
ApplicationOptions::Force => {
format!("komorebic.exe manage-rule {} \"{}\"", kind, id)
}
}
ApplicationOptions::raw_cfgen(self, kind, id)
)
}
}
@@ -118,6 +123,58 @@ impl ApplicationConfigurationGenerator {
Ok(final_cfgen)
}
pub fn generate_pwsh(
base_content: &str,
override_content: Option<&str>,
) -> Result<Vec<String>> {
let mut cfgen = if let Some(override_content) = override_content {
Self::merge(base_content, override_content)?
} else {
Self::load(base_content)?
};
cfgen.sort_by(|a, b| a.name.cmp(&b.name));
let mut lines = vec![String::from("# Generated by komorebic.exe"), String::new()];
let mut float_rules = vec![];
for app in cfgen {
lines.push(format!("# {}", app.name));
if let Some(options) = app.options {
for opt in options {
if let ApplicationOptions::TrayAndMultiWindow = opt {
lines.push(String::from("# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line"));
}
lines.push(opt.raw_cfgen(&app.identifier.kind, &app.identifier.id));
}
}
if let Some(float_identifiers) = app.float_identifiers {
for float in float_identifiers {
let float_rule =
format!("komorebic.exe float-rule {} \"{}\"", float.kind, float.id);
// Don't want to send duped signals especially as configs get larger
if !float_rules.contains(&float_rule) {
float_rules.push(float_rule.clone());
if let Some(comment) = float.comment {
lines.push(format!("# {}", comment));
};
lines.push(float_rule);
}
}
}
lines.push(String::new());
}
Ok(lines)
}
pub fn generate_ahk(base_content: &str, override_content: Option<&str>) -> Result<Vec<String>> {
let mut cfgen = if let Some(override_content) = override_content {
Self::merge(base_content, override_content)?

437
komorebi.generated.ps1 Normal file
View File

@@ -0,0 +1,437 @@
# Generated by komorebic.exe
# 1Password
komorebic.exe float-rule exe "1Password.exe"
# Adobe Creative Cloud
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application class "CreativeCloudDesktopWindowClass"
# Adobe Photoshop
komorebic.exe identify-border-overflow-application class "Photoshop"
# ArmCord
komorebic.exe identify-border-overflow-application exe "ArmCord.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ArmCord.exe"
# AutoHotkey
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "AutoHotkeyU64.exe"
komorebic.exe float-rule title "Window Spy"
# Beeper
komorebic.exe identify-border-overflow-application exe "Beeper.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Beeper.exe"
# Bitwarden
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Bitwarden.exe"
# Bloxstrap
komorebic.exe float-rule exe "Bloxstrap.exe"
# Calculator
komorebic.exe float-rule title "Calculator"
# Credential Manager UI Host
# Targets the Windows popup prompting you for a PIN instead of a password on 1Password etc.
komorebic.exe float-rule exe "CredentialUIBroker.exe"
# Cron
komorebic.exe identify-border-overflow-application exe "Cron.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Cron.exe"
# Delphi applications
# Target hidden window spawned by Delphi applications
komorebic.exe float-rule class "TApplication"
# Target Inno Setup installers
komorebic.exe float-rule class "TWizardForm"
# Discord
komorebic.exe identify-border-overflow-application exe "Discord.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Discord.exe"
# DiscordCanary
komorebic.exe identify-border-overflow-application exe "DiscordCanary.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "DiscordCanary.exe"
# DiscordDevelopment
komorebic.exe identify-border-overflow-application exe "DiscordDevelopment.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "DiscordDevelopment.exe"
# DiscordPTB
komorebic.exe identify-border-overflow-application exe "DiscordPTB.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "DiscordPTB.exe"
# ElectronMail
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ElectronMail.exe"
# Element
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Element.exe"
# ElevenClock
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ElevenClock.exe"
# Elgato Camera Hub
komorebic.exe float-rule exe "Camera Hub.exe"
# Elgato Control Center
komorebic.exe float-rule exe "ControlCenter.exe"
# Elgato Wave Link
komorebic.exe float-rule exe "WaveLink.exe"
# Epic Games Launcher
komorebic.exe identify-border-overflow-application exe "EpicGamesLauncher.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "EpicGamesLauncher.exe"
# Flow Launcher
komorebic.exe identify-border-overflow-application exe "Flow.Launcher.exe"
# GOG Galaxy
komorebic.exe identify-border-overflow-application exe "GalaxyClient.exe"
komorebic.exe manage-rule exe "GalaxyClient.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "GalaxyClient.exe"
# Targets a hidden window spawned by GOG Galaxy
komorebic.exe float-rule class "Chrome_RenderWidgetHostHWND"
# GoPro Webcam
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application class "GoPro Webcam"
# Godot Manager
komorebic.exe identify-border-overflow-application exe "GodotManager.exe"
komorebic.exe manage-rule exe "GodotManager.exe"
komorebic.exe identify-object-name-change-application exe "GodotManager.exe"
# Google Chrome
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "chrome.exe"
# Google Drive
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "GoogleDriveFS.exe"
# Houdoku
komorebic.exe identify-border-overflow-application exe "Houdoku.exe"
# IntelliJ IDEA
komorebic.exe identify-object-name-change-application exe "idea64.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "idea64.exe"
# Targets JetBrains IDE popups and floating windows
komorebic.exe float-rule class "SunAwtDialog"
# Itch.io
komorebic.exe identify-border-overflow-application exe "itch.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "itch.exe"
# Keyviz
komorebic.exe float-rule exe "keyviz.exe"
# Kleopatra
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "kleopatra.exe"
# Kotatogram
komorebic.exe identify-border-overflow-application exe "Kotatogram.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Kotatogram.exe"
# Logi Bolt
komorebic.exe float-rule exe "LogiBolt.exe"
# LogiTune
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "LogiTune.exe"
komorebic.exe float-rule exe "LogiTune.exe"
# Logitech G HUB
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "lghub.exe"
komorebic.exe identify-border-overflow-application exe "lghub.exe"
# Logitech Options
komorebic.exe float-rule exe "LogiOptionsUI.exe"
# Mailspring
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "mailspring.exe"
# ManyCam
komorebic.exe identify-border-overflow-application exe "ManyCam.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ManyCam.exe"
# Mica For Everyone
# Microsoft Excel
komorebic.exe identify-border-overflow-application exe "EXCEL.EXE"
komorebic.exe identify-layered-application exe "EXCEL.EXE"
# Targets a hidden window spawned by Microsoft Office applications
komorebic.exe float-rule class "_WwB"
# Microsoft Outlook
komorebic.exe identify-border-overflow-application exe "OUTLOOK.EXE"
komorebic.exe identify-layered-application exe "OUTLOOK.EXE"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "OUTLOOK.EXE"
# Microsoft PC Manager
komorebic.exe float-rule exe "MSPCManager.exe"
# Microsoft PowerPoint
komorebic.exe identify-border-overflow-application exe "POWERPNT.EXE"
komorebic.exe identify-layered-application exe "POWERPNT.EXE"
# Microsoft Teams
komorebic.exe identify-border-overflow-application exe "Teams.exe"
# Target Teams pop-up notification windows
komorebic.exe float-rule title "Microsoft Teams Notification"
# Target Teams call in progress windows
komorebic.exe float-rule title "Microsoft Teams Call"
# Microsoft Word
komorebic.exe identify-border-overflow-application exe "WINWORD.EXE"
komorebic.exe identify-layered-application exe "WINWORD.EXE"
# Modern Flyouts
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ModernFlyoutsHost.exe"
# Mozilla Firefox
komorebic.exe identify-object-name-change-application exe "firefox.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "firefox.exe"
# Targets invisible windows spawned by Firefox to show tab previews in the taskbar
komorebic.exe float-rule class "MozillaTaskbarPreviewClass"
# NVIDIA GeForce Experience
komorebic.exe identify-border-overflow-application exe "NVIDIA GeForce Experience.exe"
# NiceHash Miner
komorebic.exe identify-border-overflow-application exe "nhm_app.exe"
komorebic.exe manage-rule exe "nhm_app.exe"
# NohBoard
komorebic.exe float-rule exe "NohBoard.exe"
# Notion Enhanced
komorebic.exe identify-border-overflow-application exe "Notion Enhanced.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Notion Enhanced.exe"
# OBS Studio (32-bit)
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "obs32.exe"
# OBS Studio (64-bit)
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "obs64.exe"
# ONLYOFFICE Editors
komorebic.exe identify-border-overflow-application class "DocEditorsWindowClass"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application class "DocEditorsWindowClass"
# Obsidian
komorebic.exe identify-border-overflow-application exe "Obsidian.exe"
komorebic.exe manage-rule exe "Obsidian.exe"
# OpenRGB
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "OpenRGB.exe"
# Paradox Launcher
komorebic.exe float-rule exe "Paradox Launcher.exe"
# PowerToys
# Target color picker dialog
komorebic.exe float-rule exe "PowerToys.ColorPickerUI.exe"
# Target image resizer dialog
komorebic.exe float-rule exe "PowerToys.ImageResizer.exe"
# Process Hacker
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ProcessHacker.exe"
komorebic.exe float-rule exe "ProcessHacker.exe"
# ProtonVPN
komorebic.exe identify-border-overflow-application exe "ProtonVPN.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ProtonVPN.exe"
# PyCharm
komorebic.exe identify-object-name-change-application exe "pycharm64.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "pycharm64.exe"
# QuickLook
komorebic.exe float-rule exe "QuickLook.exe"
# RepoZ
komorebic.exe float-rule exe "RepoZ.exe"
# Roblox FPS Unlocker
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "rbxfpsunlocker.exe"
# RoundedTB
komorebic.exe float-rule exe "RoundedTB.exe"
# RoundedTB
komorebic.exe identify-border-overflow-application exe "RoundedTB.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "RoundedTB.exe"
# ShareX
komorebic.exe identify-border-overflow-application exe "ShareX.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ShareX.exe"
# Signal
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "signal.exe"
# SiriKali
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "sirikali.exe"
# Slack
komorebic.exe identify-border-overflow-application exe "Slack.exe"
komorebic.exe manage-rule exe "Slack.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Slack.exe"
# Slack
komorebic.exe identify-border-overflow-application exe "slack.exe"
komorebic.exe manage-rule exe "slack.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "slack.exe"
# Smart Install Maker
# Target hidden window spawned by installer
komorebic.exe float-rule class "obj_App"
# Target installer
komorebic.exe float-rule class "obj_Form"
# SoulseekQt
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "SoulseekQt.exe"
# Spotify
komorebic.exe identify-border-overflow-application exe "Spotify.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Spotify.exe"
# Steam
komorebic.exe identify-border-overflow-application class "vguiPopupWindow"
# Stremio
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "stremio.exe"
# System Informer
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "SystemInformer.exe"
komorebic.exe float-rule exe "SystemInformer.exe"
# SystemSettings
komorebic.exe float-rule class "Shell_Dialog"
# Task Manager
komorebic.exe float-rule class "TaskManagerWindow"
# Telegram
komorebic.exe identify-border-overflow-application exe "Telegram.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "Telegram.exe"
# TouchCursor
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "tcconfig.exe"
komorebic.exe float-rule exe "tcconfig.exe"
# TranslucentTB
komorebic.exe float-rule exe "TranslucentTB.exe"
# TranslucentTB
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "TranslucentTB.exe"
# Unreal Editor
komorebic.exe identify-border-overflow-application exe "UnrealEditor.exe"
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "UnrealEditor.exe"
# Visual Studio
komorebic.exe identify-object-name-change-application exe "devenv.exe"
# Visual Studio Code
komorebic.exe identify-border-overflow-application exe "Code.exe"
# WebTorrent Desktop
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "WebTorrent.exe"
# Windows Console (conhost.exe)
komorebic.exe manage-rule class "ConsoleWindowClass"
# Windows Explorer
# Targets copy/move operation windows
komorebic.exe float-rule class "OperationStatusWindow"
komorebic.exe float-rule title "Control Panel"
# Windows Installer
# Targets MSI Installers
komorebic.exe float-rule class "MsiDialogCloseClass"
# WingetUI
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "WingetUI.exe"
# WingetUI
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "wingetui.exe"
# Wox
# Targets a hidden window spawned by Wox
komorebic.exe float-rule title "Hotkey sink"
# XAMPP Control Panel
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "xampp-control.exe"
# Zoom
komorebic.exe float-rule exe "Zoom.exe"
# mpv.net
komorebic.exe identify-object-name-change-application exe "mpvnet.exe"
# paint.net
komorebic.exe float-rule exe "paintdotnet.exe"
# pinentry
komorebic.exe float-rule exe "pinentry.exe"
# qBittorrent
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "qbittorrent.exe"
# ueli
# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
komorebic.exe identify-tray-application exe "ueli.exe"
komorebic.exe float-rule exe "ueli.exe"

31
komorebi.sample.ps1 Normal file
View File

@@ -0,0 +1,31 @@
if (!(Get-Process whkd -ErrorAction SilentlyContinue))
{
Start-Process whkd -WindowStyle hidden
}
. $PSScriptRoot\komorebi.generated.ps1
# Default to minimizing windows when switching workspaces
komorebic window-hiding-behaviour minimize
# Set cross-monitor move behaviour to insert instead of swap
komorebic cross-monitor-move-behaviour insert
# Enable hot reloading of changes to this file
komorebic watch-configuration enable
# Configure the invisible border dimensions
komorebic invisible-borders 7 0 14 7
# Ensure there is 1 workspace created on monitor 0
komorebic ensure-workspaces 0 1
# Configure the 1st workspace on the 1st monitor
komorebic workspace-name 0 0 "I"
komorebic workspace-layout 0 0 bsp
komorebic container-padding 0 0 bsp
# Uncomment the next lines if you want a visual border around the active window
# komorebic active-window-border-colour 66 165 245 --window-kind single
# komorebic active-window-border-colour 256 165 66 --window-kind stack
# komorebic active-window-border enable
komorebic complete-configuration

View File

@@ -248,13 +248,34 @@ fn setup() -> Result<(WorkerGuard, WorkerGuard)> {
pub fn load_configuration() -> Result<()> {
let home = HOME_DIR.clone();
let mut config_pwsh = home.clone();
config_pwsh.push("komorebi.ps1");
let mut config_v1 = home.clone();
config_v1.push("komorebi.ahk");
let mut config_v2 = home;
config_v2.push("komorebi.ahk2");
if config_v1.exists() && which(&*AHK_V1_EXE).is_ok() {
if config_pwsh.exists() {
let powershell_exe = if which("pwsh.exe").is_ok() {
"pwsh.exe"
} else {
"powershell.exe"
};
tracing::info!(
"loading configuration file: {}",
config_pwsh
.as_os_str()
.to_str()
.ok_or_else(|| anyhow!("cannot convert path to string"))?
);
Command::new(powershell_exe)
.arg(config_pwsh.as_os_str())
.output()?;
} else if config_v1.exists() && which(&*AHK_V1_EXE).is_ok() {
tracing::info!(
"loading configuration file: {}",
config_v1

View File

@@ -230,13 +230,18 @@ impl WindowManager {
pub fn watch_configuration(&mut self, enable: bool) -> Result<()> {
let home = HOME_DIR.clone();
let mut config_pwsh = home.clone();
config_pwsh.push("komorebi.ps1");
let mut config_v1 = home.clone();
config_v1.push("komorebi.ahk");
let mut config_v2 = home;
config_v2.push("komorebi.ahk2");
if config_v1.exists() {
if config_pwsh.exists() {
self.configure_watcher(enable, config_pwsh)?;
} else if config_v1.exists() {
self.configure_watcher(enable, config_v1)?;
} else if config_v2.exists() {
self.configure_watcher(enable, config_v2)?;

View File

@@ -428,6 +428,10 @@ AhkAppSpecificConfiguration(path, override_path) {
RunWait, komorebic.exe ahk-app-specific-configuration %path% %override_path%, , Hide
}
PwshAppSpecificConfiguration(path, override_path) {
RunWait, komorebic.exe pwsh-app-specific-configuration %path% %override_path%, , Hide
}
FormatAppSpecificConfiguration(path) {
RunWait, komorebic.exe format-app-specific-configuration %path%, , Hide
}

View File

@@ -626,6 +626,14 @@ struct AhkAppSpecificConfiguration {
override_path: Option<String>,
}
#[derive(Parser, AhkFunction)]
struct PwshAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
path: String,
/// Optional YAML file of overrides to apply over the first file
override_path: Option<String>,
}
#[derive(Parser, AhkFunction)]
struct FormatAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
@@ -948,6 +956,10 @@ enum SubCommand {
#[clap(arg_required_else_help = true)]
#[clap(alias = "ahk-asc")]
AhkAppSpecificConfiguration(AhkAppSpecificConfiguration),
/// Generate common app-specific configurations and fixes in a PowerShell script
#[clap(arg_required_else_help = true)]
#[clap(alias = "pwsh-asc")]
PwshAppSpecificConfiguration(PwshAppSpecificConfiguration),
/// Format a YAML file for use with the 'ahk-app-specific-configuration' command
#[clap(arg_required_else_help = true)]
#[clap(alias = "fmt-asc")]
@@ -1692,6 +1704,36 @@ fn main() -> Result<()> {
println!("\n#Include %A_ScriptDir%\\komorebi.generated.ahk");
}
SubCommand::PwshAppSpecificConfiguration(arg) => {
let content = fs::read_to_string(resolve_windows_path(&arg.path)?)?;
let lines = if let Some(override_path) = arg.override_path {
let override_content = fs::read_to_string(resolve_windows_path(&override_path)?)?;
ApplicationConfigurationGenerator::generate_pwsh(
&content,
Option::from(override_content.as_str()),
)?
} else {
ApplicationConfigurationGenerator::generate_pwsh(&content, None)?
};
let mut generated_config = HOME_DIR.clone();
generated_config.push("komorebi.generated.ps1");
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(generated_config.clone())?;
file.write_all(lines.join("\n").as_bytes())?;
println!(
"\nApplication-specific generated configuration written to {}",
generated_config.to_str().ok_or_else(|| anyhow!(
"could not find the path to the generated configuration file"
))?
);
}
SubCommand::FormatAppSpecificConfiguration(arg) => {
let file_path = resolve_windows_path(&arg.path)?;
let content = std::fs::read_to_string(&file_path)?;

67
swhkdrc.sample Normal file
View File

@@ -0,0 +1,67 @@
.shell pwsh
# reload swhkd configuration
# alt + o : taskkill /f /im swhkd.exe && start /b swhkd # if shell is cmd
alt + o : taskkill /f /im swhkd.exe && Start-Process swhkd -WindowStyle hidden # if shell is pwsh / powershell
alt + shift + o : komorebic reload-configuration
# app shortcuts - these require shell to be pwsh / powershell
# the apps will be focused if open, or launched if not open
# alt + f : if ($wshell.AppActivate('Firefox') -eq $False) { start firefox }
# alt + b : if ($wshell.AppActivate('Chrome') -eq $False) { start chrome }
# focus windows
alt + h : komorebic focus left
alt + j : komorebic focus down
alt + k : komorebic focus up
alt + l : komorebic focus right
alt + oem_1 : komorebic force-focus # oem_1 is ;
alt + u : komorebic cycle-focus previous
alt + i : komorebic cycle-focus next
# move windows
alt + shift + h : komorebic move left
alt + shift + j : komorebic move down
alt + shift + k : komorebic move up
alt + shift + l : komorebic move right
alt + shift + return : komorebic promote
# stack windows
alt + shift + left : komorebic stack left
alt + shift + down : komorebic stack down
alt + shift + up : komorebic stack up
alt + shift + right : komorebic stack right
alt + shift + d : komorebic unstack
alt + i : komorebic cycle-stack next
alt + u : komorebic cycle-stack previous
# resize
alt + oem_plus : komorebic resize-axis horizontal increase
alt + oem_minus : komorebic resize-axis horizontal decrease
alt + shift + oem_plus : komorebic resize-axis vertical increase
alt + shift + oem_minus : komorebic resize-axis vertical decrease
# manipulate windows
alt + t : komorebic toggle-float
alt + shift + f : komorebic toggle-monocle
# window manager options
alt + shift + r : komorebic retile
alt + p : komorebic toggle-pause
alt + 0 : komorebic toggle-focus-follows-mouse
# layouts
alt + x : komorebic flip-layout horizontal
alt + y : komorebic flip-layout vertical
# workspaces
alt + 1 : komorebic focus-workspace 0
alt + 2 : komorebic focus-workspace 1
alt + 3 : komorebic focus-workspace 2
alt + 4 : komorebic focus-workspace 3
# move windows across workspaces
alt + shift + 1 : komorebic move-to-workspace 0
alt + shift + 2 : komorebic move-to-workspace 1
alt + shift + 3 : komorebic move-to-workspace 2
alt + shift + 4 : komorebic move-to-workspace 3