Files
dotfiles/.config/kitty/get_cwd.sh
Julian Prein a34a00eae6 i3: Fix opening kitty in the current working dir
Since I run kitty with --single-instance, xcwd does not work for it.
Replace it with a short script that retrieves the CWD for the focused
window through the remote-control ls command.

This changes the current behaviour slightly, since now only terminals
are used and not any X window (which I rarely used or needed) and that
the working dir of the shell running in kitty will be used and not of
any deeper children. I'm still unsure if I want the latter back, but
will figure this out in the future.

This is an addendum to 0139294831 ("Use kitty instead of st as
terminal").
2025-05-27 18:24:06 +02:00

24 lines
699 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Print the current working directory of the focused kitty window. Returns 4 if
# none exist or is focused.
# NOTE: the backticks are used for hacky line-continuation, taken from
# https://stackoverflow.com/a/7729087/2092762c9
kitten @ --to unix:/tmp/mykitty ls \
| jq -er ".[]`
` | 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"