diff --git a/.config/kitty/get_cwd.sh b/.config/kitty/get_cwd.sh index 3e29f61..694feb2 100755 --- a/.config/kitty/get_cwd.sh +++ b/.config/kitty/get_cwd.sh @@ -9,13 +9,19 @@ 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 -kitten @ --to unix:"$socket_path" ls \ - | jq -er ".[]` - ` | select(.is_focused).tabs.[]` - ` | select(.is_focused).windows.[]` - ` | select(.is_focused).cwd" +printf '\eP@kitty-cmd{"cmd":"ls","version":[0,26,0]}\e\\' \ +| 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: