From 3a821d832b749131c608c68e3b7d1c779e493f1f Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 11 Dec 2025 15:23:26 +0100 Subject: [PATCH] kitty:get_cwd: Use the match flag for performance Instead of requesting the full tree as a JSON and extracting the focused window with `jq`, use `kitten-@-ls`'s `--match` flag. This further improves the performance. Also remove the commented code using recursive descent because it is not up-to-date anymore. --- .config/kitty/get_cwd.sh | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/.config/kitty/get_cwd.sh b/.config/kitty/get_cwd.sh index 694feb2..c89ab6a 100755 --- a/.config/kitty/get_cwd.sh +++ b/.config/kitty/get_cwd.sh @@ -11,23 +11,10 @@ socket_path="${TMPDIR:-/tmp}/kitty.$USER/kitty${1:+-$1}.sock" # NOTE: Unfortunately kitten-@-ls(1) is slow, so communicate with the socket # directly. -# NOTE: the backticks are used for hacky line-continuation, taken from -# https://stackoverflow.com/a/7729087/2092762c9 -printf '\eP@kitty-cmd{"cmd":"ls","version":[0,26,0]}\e\\' \ +printf '\eP@kitty-cmd{%s,%s,%s}\e\\' \ + '"cmd":"ls"' \ + '"version":[0,26,0]' \ + '"payload":{"match":"state:focused"}' \ | nc -U -q0 "$socket_path" \ | awk '{ print substr($0, 13, length($0) - 14) }' \ -| jq -er ".data` - ` | fromjson` - ` | .[]` - ` | select(.is_focused).tabs.[]` - ` | select(.is_focused).windows.[]` - ` | select(.is_focused).cwd" - -# An alternative version that uses recursive descent to find focused objects -# that also have a `.cwd` key: -# -# | jq -er "..` -# ` | objects` -# ` | select(.is_focused)` -# ` | to_entries.[]` -# ` | select(.key == \"cwd\").value" +| jq -er ".data | fromjson | .[].tabs.[].windows.[].cwd"