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:
12 files changed
+425
-6
No files matched your search
@@ -47,6 +47,27 @@ sorted by last modification time, most recent first.
|
||||
|
||||
egr()
|
||||
|
||||
agr('shell', 'Shell synchronisation')
|
||||
|
||||
opt(
|
||||
'sync_cwd',
|
||||
'no',
|
||||
option_type='to_bool',
|
||||
long_text="""
|
||||
Keep the shell's working directory and the panel in step. A :code:`cd` in the
|
||||
shell moves the panel to the same directory, and validating a directory in the
|
||||
panel makes the shell change to it at its next prompt.
|
||||
|
||||
The exchange goes through two small files in the session directory kitty
|
||||
exports as :envvar:`KITTY_CWD_SYNC_DIR`, so nothing is typed into the shell:
|
||||
the command never lands in the history and a half typed multi-line command is
|
||||
left untouched. Bash, zsh and fish are supported by their kitty shell
|
||||
integration; other shells keep the current behaviour.
|
||||
""",
|
||||
)
|
||||
|
||||
egr()
|
||||
|
||||
agr('opening', 'Opening files')
|
||||
|
||||
opt(
|
||||
@@ -196,6 +217,10 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int,
|
||||
action, path = data.get('action'), data.get('path')
|
||||
if action != 'cd' or not path:
|
||||
return
|
||||
if data.get('sync'):
|
||||
# The panel published the directory in the session file and the shell
|
||||
# picks it up from its prompt hook, see the sync_cwd option.
|
||||
return
|
||||
w = boss.window_id_map.get(target_window_id)
|
||||
if w is None:
|
||||
boss.ring_bell_if_allowed()
|
||||
|
||||
Reference in new issue
Block a user