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

+25
View File
@@ -246,6 +246,31 @@ _ksi_deferred_init() {
_ksi_report_pwd
fi
# 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 [[ -n $KITTY_CWD_SYNC_DIR && -n $KITTY_WINDOW_ID && -d $KITTY_CWD_SYNC_DIR ]]; then
builtin typeset -g _ksi_cwd_sync_file="$KITTY_CWD_SYNC_DIR/$KITTY_WINDOW_ID"
_ksi_cwd_sync_publish() { builtin print -rn -- "$PWD" >| "$_ksi_cwd_sync_file" 2> /dev/null; }
_ksi_cwd_sync_apply() {
builtin local -i ret=$?
builtin local target
if [[ -f "$_ksi_cwd_sync_file.set" ]]; then
IFS= builtin read -r target < "$_ksi_cwd_sync_file.set"
builtin command rm -f -- "$_ksi_cwd_sync_file.set"
if [[ -n $target && -d $target ]]; then
builtin cd -- "$target"
fi
fi
_ksi_cwd_sync_publish
builtin return ret
}
_ksi_cwd_sync_publish
precmd_functions+=(_ksi_cwd_sync_apply)
chpwd_functions+=(_ksi_cwd_sync_publish)
fi
# Enable terminal title changes.
if (( ! opt[(Ie)no-title] )); then
# We don't use `print -P` because it depends on prompt options, which