feat(file-manager): sync the working directory with the shell

The panel and the shell each kept their own directory. The new sync_cwd option
keeps them in step both ways, through files in a session directory exported by
kitty rather than by typing a command into the terminal: the shell applies the
directory chosen in the panel from its prompt hook with builtin cd, so nothing
lands in the history and a half typed multi-line command is not submitted.
This commit is contained in:
BlackAngelTV committed 2026-11-11 08:20:11 +01:00
1 parent f16ed6cbfe
commit 1b330bcf81
12 files changed
+425 -6

No files matched your search

@@ -137,6 +137,28 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after
__update_cwd_osc
end
# Optional working directory sync with the file manager panel (sync_cwd).
# The panel publishes the directory it wants in <dir>/<window id>.set and we
# apply it at prompt time instead of typing a cd into the terminal, see the
# bash integration for the rationale.
if set -q KITTY_CWD_SYNC_DIR; and set -q KITTY_WINDOW_ID; and test -d "$KITTY_CWD_SYNC_DIR"
function __ksi_cwd_sync_publish --on-event fish_prompt -d "Publish the working directory for the file manager panel"
printf '%s' "$PWD" > "$KITTY_CWD_SYNC_DIR/$KITTY_WINDOW_ID" 2> /dev/null
end
function __ksi_cwd_sync_apply --on-event fish_prompt -d "Apply a directory chosen in the file manager panel"
set --local file "$KITTY_CWD_SYNC_DIR/$KITTY_WINDOW_ID.set"
if test -f "$file"
set --local target (cat "$file")
rm -f -- "$file"
if test -n "$target" -a -d "$target"
builtin cd -- "$target"
end
end
__ksi_cwd_sync_publish
end
__ksi_cwd_sync_publish
end
# Note that neither alias nor function is recursive in fish so if the user defines an alias/function
# for sudo/run0 it will be clobbered by us, so only install these if they are not already functions
if not contains "no-sudo" $_ksi