diff --git a/kitty/launch.py b/kitty/launch.py index c5762ac77..7f34a6b20 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -14,7 +14,7 @@ from .tabs import Tab, TabManager from .types import run_once from .utils import log_error, resolve_custom_file, set_primary_selection, which -from .window import CwdRequest, Watchers, Window +from .window import CwdRequest, CwdRequestType, Watchers, Window try: from typing import TypedDict @@ -62,6 +62,8 @@ def options_spec() -> str: --cwd The working directory for the newly launched child. Use the special value :code:`current` to use the working directory of the currently active window. +The special value :code:`last_reported` uses the last working directory +reported by the shell (needs :ref:`shell_integration` to work). --env @@ -359,6 +361,9 @@ def launch( if opts.cwd == 'current': if active: kw['cwd_from'] = CwdRequest(active) + elif opts.cwd == 'last_reported': + if active: + kw['cwd_from'] = CwdRequest(active, CwdRequestType.last_reported) else: kw['cwd'] = opts.cwd if opts.location != 'default': diff --git a/kitty/window.py b/kitty/window.py index 57c4fd6b5..80bba945d 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -78,6 +78,10 @@ def modify_argv_for_launch_with_cwd(self, argv: List[str]) -> str: @property def cwd_of_child(self) -> Optional[str]: window = get_boss().window_id_map.get(self.window_id) + if window and self.request_type is CwdRequestType.last_reported and window.screen.last_reported_cwd: + cwd = path_from_osc7_url(window.screen.last_reported_cwd) + if cwd: + return cwd return window.cwd_of_child if window else None