kitty:get_cwd: Make faster by not using kitten
kitten-@-ls(1) is unfortunately a bit slow (100ms) which is noticeable when launching new windows using `get_cwd`. Make `get_cwd` faster (down to 25ms) by communicating directly with the socket instead of using `kitten`.
This commit is contained in:
@@ -9,10 +9,16 @@
|
|||||||
|
|
||||||
socket_path="${TMPDIR:-/tmp}/kitty.$USER/kitty${1:+-$1}.sock"
|
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
|
# NOTE: the backticks are used for hacky line-continuation, taken from
|
||||||
# https://stackoverflow.com/a/7729087/2092762c9
|
# https://stackoverflow.com/a/7729087/2092762c9
|
||||||
kitten @ --to unix:"$socket_path" ls \
|
printf '\eP@kitty-cmd{"cmd":"ls","version":[0,26,0]}\e\\' \
|
||||||
| jq -er ".[]`
|
| nc -U -q0 "$socket_path" \
|
||||||
|
| awk '{ print substr($0, 13, length($0) - 14) }' \
|
||||||
|
| jq -er ".data`
|
||||||
|
` | fromjson`
|
||||||
|
` | .[]`
|
||||||
` | select(.is_focused).tabs.[]`
|
` | select(.is_focused).tabs.[]`
|
||||||
` | select(.is_focused).windows.[]`
|
` | select(.is_focused).windows.[]`
|
||||||
` | select(.is_focused).cwd"
|
` | select(.is_focused).cwd"
|
||||||
|
|||||||
Reference in New Issue
Block a user