From afa6128155630e7506f4ad229eccb84bbd8731fb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Mar 2022 10:29:31 +0530 Subject: [PATCH] Implement --cwd=last_reported --- kitty/launch.py | 7 ++++++- kitty/window.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 .options.utils import env as parse_env 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 @@ to the newly opened window. --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 @@ class CwdRequest: @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