Skip to content

fixed the omarchy-cmd-terminal-cwd for kitty#6315

Closed
xmagma-x wants to merge 1 commit into
basecamp:quattrofrom
xmagma-x:terminal-cwd-fix-kitty
Closed

fixed the omarchy-cmd-terminal-cwd for kitty#6315
xmagma-x wants to merge 1 commit into
basecamp:quattrofrom
xmagma-x:terminal-cwd-fix-kitty

Conversation

@xmagma-x

@xmagma-x xmagma-x commented Jul 19, 2026

Copy link
Copy Markdown

Title:
Fix omarchy-cmd-terminal-cwd to correctly detect cwd for Kitty terminal
Description:

Problem

omarchy-cmd-terminal-cwd always returns $HOME when used from Kitty terminal, making the keybinding SUPER+SHIFT+ALT+F (which uses $(omarchy-cmd-terminal-cwd)) useless.

Root Cause

Three issues with the original script when running under Kitty:

  1. Kitty's client-server architecture: Kitty uses a daemon that spawns tabs/windows as child processes. hyprctl activewindow returns the Kitty window PID, but that PID belongs to the Kitty daemon — not the shell process inside the window. The daemon has no direct cwd.

  2. /proc/$pid/children doesn't exist: The original script tried to read /proc/$pid/children to walk the process tree, but this file does not exist on all kernels despite CONFIG_PROC_CHILDREN=y. Using pgrep -P is the reliable alternative.

  3. IFS null-byte issue: The system's default IFS includes a null byte, which causes for child in $children to silently fail. Using while IFS= read -r fixes this.

Changes

  • Kitty detection: Added class-based check via hyprctl activewindow to detect Kitty.
  • Primary path for Kitty: Uses kitty @ ls + jq to query the focused window's shell PID and cwd directly via Kitty's remote control protocol.
  • Fallback for Kitty: When kitty @ ls fails (e.g., missing KITTY_PUBLIC_KEY in keybinding context), extracts the daemon PID from systemd transient scopes (/run/user/$UID/systemd/transient/kitty-*.scope), then recursively walks the process tree via pgrep -P to find the deepest shell.
  • Non-Kitty terminals: Uses recursive pgrep -P walking instead of /proc/$pid/children.
  • IFS fix: All child iteration uses while IFS= read -r to handle null bytes in IFS correctly.
    PR body (markdown):

Problem

omarchy-cmd-terminal-cwd always returns $HOME when used from Kitty terminal, making the SUPER+SHIFT+ALT+F keybinding useless.

Root Cause

Three issues under Kitty:

  1. Kitty's client-server architecture: hyprctl activewindow returns the Kitty daemon PID, which has no direct cwd.
  2. /proc/$pid/children doesn't exist: Not available on all kernels. pgrep -P is the reliable alternative.
  3. IFS null-byte: System default IFS includes a null byte, breaking for child in $children. Fixed with while IFS= read -r.

Solution

  • Kitty primary path: kitty @ ls + jq to get focused window's shell PID and cwd.
  • Kitty fallback: Extract daemon PID from systemd transient scopes, recursively walk children via pgrep -P.
  • Non-Kitty: Recursive pgrep -P instead of /proc/$pid/children.
  • IFS fix: All child iteration uses while IFS= read -r.

Testing

Verified working on Kitty 0.47.4 with both manual command execution and the SUPER+SHIFT+ALT+F keybinding.

Copilot AI review requested due to automatic review settings July 19, 2026 12:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dhh

dhh commented Jul 19, 2026

Copy link
Copy Markdown
Member

Thanks for reporting this. Fixed in 008f3a22 using a smaller deterministic approach: Kitty gets a per-process remote-control socket, and the cwd helper queries only state:focused while preserving the existing fallback for other terminals.

@dhh dhh closed this Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants