|
| 1 | +{{ if eq .chezmoi.os "windows" -}} |
| 2 | +# Komorebi config hashes (trigger re-run when configs change): |
| 3 | +# komorebi.json: {{ include "dot_config/komorebi/komorebi.json" | sha256sum }} |
| 4 | +# whkdrc: {{ include "dot_config/whkdrc" | sha256sum }} |
| 5 | + |
| 6 | +$ErrorActionPreference = "Stop" |
| 7 | + |
| 8 | +function Resolve-KomorebicPath { |
| 9 | + $cmd = Get-Command komorebic.exe -ErrorAction SilentlyContinue |
| 10 | + if (-not $cmd) { |
| 11 | + $cmd = Get-Command komorebic -ErrorAction SilentlyContinue |
| 12 | + } |
| 13 | + if ($cmd -and -not [string]::IsNullOrWhiteSpace($cmd.Source)) { |
| 14 | + return $cmd.Source |
| 15 | + } |
| 16 | + |
| 17 | + $candidates = @( |
| 18 | + "$env:USERPROFILE\scoop\shims\komorebic.exe", |
| 19 | + "$env:LOCALAPPDATA\Microsoft\WinGet\Links\komorebic.exe", |
| 20 | + "$env:ProgramFiles\komorebi\bin\komorebic.exe" |
| 21 | + ) |
| 22 | + return ($candidates | Where-Object { |
| 23 | + -not [string]::IsNullOrWhiteSpace($_) -and (Test-Path $_) |
| 24 | + } | Select-Object -First 1) |
| 25 | +} |
| 26 | + |
| 27 | +$komorebic = Resolve-KomorebicPath |
| 28 | + |
| 29 | +if (Get-Process -Name "komorebi" -ErrorAction SilentlyContinue) { |
| 30 | + if (-not $komorebic) { |
| 31 | + Write-Host "Komorebi process found but komorebic could not be resolved; skipping reload." -ForegroundColor DarkGray |
| 32 | + return |
| 33 | + } |
| 34 | + Write-Host "Reloading Komorebi configuration..." |
| 35 | + & $komorebic reload-configuration |
| 36 | + if ($LASTEXITCODE -ne 0) { |
| 37 | + throw "Komorebi reload failed (exit code $LASTEXITCODE)." |
| 38 | + } |
| 39 | + |
| 40 | + # whkd has no live-reload — restart it so new whkdrc takes effect. |
| 41 | + if (Get-Process -Name "whkd" -ErrorAction SilentlyContinue) { |
| 42 | + Write-Host "Restarting whkd to pick up new keybindings..." |
| 43 | + Stop-Process -Name "whkd" -Force -ErrorAction SilentlyContinue |
| 44 | + Start-Sleep -Milliseconds 500 |
| 45 | + $whkdCmd = Get-Command whkd.exe -ErrorAction SilentlyContinue |
| 46 | + if ($whkdCmd) { |
| 47 | + Start-Process -FilePath $whkdCmd.Source -WindowStyle Hidden |
| 48 | + } |
| 49 | + } |
| 50 | +} else { |
| 51 | + if (-not $komorebic) { |
| 52 | + Write-Host "Komorebi not found; skipping reload." -ForegroundColor DarkGray |
| 53 | + return |
| 54 | + } |
| 55 | + Write-Host "Komorebi is installed but not running; skipping reload." -ForegroundColor DarkGray |
| 56 | +} |
| 57 | +{{- end }} |
0 commit comments