Files
dotfiles/.config/kitty/get_cwd.sh
Julian Prein 3a821d832b 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.
2025-12-11 15:27:38 +01:00

21 lines
636 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Usage: kitty-cwd [GROUP_NAME]
#
# Print the current working directory of the focused kitty window. Returns 4 if
# none exist or is focused.
socket_path="${TMPDIR:-/tmp}/kitty.$USER/kitty${1:+-$1}.sock"
# NOTE: Unfortunately kitten-@-ls(1) is slow, so communicate with the socket
# directly.
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 | .[].tabs.[].windows.[].cwd"