Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: komorebic stop --ahk doesn't stop autohotkey because of trailing space in command line #1174

Open
Ziron opened this issue Dec 14, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Ziron
Copy link

Ziron commented Dec 14, 2024

Summary

Hello, when the AHK option is used and trying to stop the program, komorebi does not find the autohotkey process to stop it because there is a trailing space in the command line so the ($_.CommandLine -like '*komorebi.ahk"') condition does not match.

Output when trying to stop the script:

PS C:\Users\Sebbe> komorebic stop --ahk

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'))
    } | 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'))
    } | Select-Object -First 1) | ForEach-Object {
        Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue
    }
}

komorebi is still running, attempting to force-quit

Stop-Process -Name:komorebi -ErrorAction SilentlyContinue

Empty output of original command:

PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     }

Output of modified command:

PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"*') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     } | Select-Object Name,Commandline

Name             Commandline
----             -----------
AutoHotkey64.exe "C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" "C:\Users\Sebbe\Documents\Komorebi\komorebi.ahk"

Command line as hex bytes to show the hidden trailing space (0x20):

PS C:\Users\Sebbe> (Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"*') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     }).Commandline | Format-Hex

   Label: String (System.String) <12494C45>

          Offset Bytes                                           Ascii
                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 22 43 3A 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 "C:\Program File
0000000000000010 73 5C 41 75 74 6F 48 6F 74 6B 65 79 5C 76 32 5C s\AutoHotkey\v2\
0000000000000020 41 75 74 6F 48 6F 74 6B 65 79 36 34 2E 65 78 65 AutoHotkey64.exe
0000000000000030 22 20 22 43 3A 5C 55 73 65 72 73 5C 53 65 62 62 " "C:\Users\Sebb
0000000000000040 65 5C 44 6F 63 75 6D 65 6E 74 73 5C 4B 6F 6D 6F e\Documents\Komo
0000000000000050 72 65 62 69 5C 6B 6F 6D 6F 72 65 62 69 2E 61 68 rebi\komorebi.ah
0000000000000060 6B 22 20                                        k"

Version Information

OS Name:                       Microsoft Windows 11 Pro
OS Version:                    10.0.26100 N/A Build 26100

komorebic 0.1.30
tag:v0.1.30
commit_hash:9a3dbccc
build_time:2024-11-03 23:49:52 +00:00
build_env:rustc 1.82.0 (f6e511eec 2024-10-15),stable-x86_64-pc-windows-msvc

Komorebi Configuration

{
  "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.30/schema.json",
  "app_specific_configuration_path": "$Env:KOMOREBI_CONFIG_HOME/applications.json",
  "window_hiding_behaviour": "Cloak",
  "cross_monitor_move_behaviour": "Insert",
  "default_workspace_padding": 20,
  "default_container_padding": 20,
  "border": true,
  "border_width": 8,
  "border_offset": -1,
  "theme": {
    "palette": "Base16",
    "name": "Ashes",
    "unfocused_border": "Base03",
    "bar_accent": "Base0D"
  },
  "stackbar": {
    "height": 40,
    "mode": "OnStack",
    "tabs": {
      "width": 300
    }
  },
  "monitors": [
    {
      "workspaces": [
        {
          "name": "I",
          "layout": "BSP"
        },
        {
          "name": "II",
          "layout": "VerticalStack"
        },
        {
          "name": "III",
          "layout": "HorizontalStack"
        },
        {
          "name": "IV",
          "layout": "UltrawideVerticalStack"
        },
        {
          "name": "V",
          "layout": "Rows"
        },
        {
          "name": "VI",
          "layout": "Grid"
        },
        {
          "name": "VII",
          "layout": "RightMainVerticalStack"
        }
      ]
    }
  ]
}

Hotkey Configuration

#Requires AutoHotkey v2.0.2
#SingleInstance Force

Komorebic(cmd) {
    RunWait(format("komorebic.exe {}", cmd), , "Hide")
}

!q::Komorebic("close")
!m::Komorebic("minimize")

; Focus windows
!h::Komorebic("focus left")
!j::Komorebic("focus down")
!k::Komorebic("focus up")
!l::Komorebic("focus right")

!+[::Komorebic("cycle-focus previous")
!+]::Komorebic("cycle-focus next")

; Move windows
!+h::Komorebic("move left")
!+j::Komorebic("move down")
!+k::Komorebic("move up")
!+l::Komorebic("move right")

; Stack windows
!Left::Komorebic("stack left")
!Down::Komorebic("stack down")
!Up::Komorebic("stack up")
!Right::Komorebic("stack right")
!;::Komorebic("unstack")
![::Komorebic("cycle-stack previous")
!]::Komorebic("cycle-stack next")

; Resize
!=::Komorebic("resize-axis horizontal increase")
!-::Komorebic("resize-axis horizontal decrease")
!+=::Komorebic("resize-axis vertical increase")
!+_::Komorebic("resize-axis vertical decrease")

; Manipulate windows
!t::Komorebic("toggle-float")
!f::Komorebic("toggle-monocle")

; Window manager options
!+r::Komorebic("retile")
!p::Komorebic("toggle-pause")

; Layouts
!x::Komorebic("flip-layout horizontal")
!y::Komorebic("flip-layout vertical")

; Workspaces
!1::Komorebic("focus-workspace 0")
!2::Komorebic("focus-workspace 1")
!3::Komorebic("focus-workspace 2")
!4::Komorebic("focus-workspace 3")
!5::Komorebic("focus-workspace 4")
!6::Komorebic("focus-workspace 5")
!7::Komorebic("focus-workspace 6")
!8::Komorebic("focus-workspace 7")

; Move windows across workspaces
!+1::Komorebic("move-to-workspace 0")
!+2::Komorebic("move-to-workspace 1")
!+3::Komorebic("move-to-workspace 2")
!+4::Komorebic("move-to-workspace 3")
!+5::Komorebic("move-to-workspace 4")
!+6::Komorebic("move-to-workspace 5")
!+7::Komorebic("move-to-workspace 6")
!+8::Komorebic("move-to-workspace 7")

Output of komorebic check

KOMOREBI_CONFIG_HOME detected: C:\Users\Sebbe\Documents\Komorebi

Looking for configuration files in C:\Users\Sebbe\Documents\Komorebi

Found komorebi.json; this file can be passed to the start command with the --config flag

No ~/.config/whkdrc found; you may not be able to control komorebi with your keyboard
@Ziron Ziron added the bug Something isn't working label Dec 14, 2024
@Ziron
Copy link
Author

Ziron commented Dec 14, 2024

Looks like it is known behavior that using Start-Process adds an extra space at the end of the commandline: PowerShell/PowerShell#13094

@LGUG2Z
Copy link
Owner

LGUG2Z commented Dec 14, 2024

Thanks for the deep dive here @Ziron! If someone would like to rewrite this logic in pure Rust to avoid the PowerShell issue I'd be willing to accept a patch.

@LGUG2Z LGUG2Z added the help wanted Extra attention is needed label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants