Allow using the cwd of the original process for launch --cwd
Fixes #5672
This commit is contained in:
parent
d54fe3c16a
commit
d9215feda5
@ -45,6 +45,8 @@ Detailed list of changes
|
|||||||
- Speed up the ``kitty @`` executable by ~10x reducing the time for typical
|
- Speed up the ``kitty @`` executable by ~10x reducing the time for typical
|
||||||
remote control commands from ~50ms to ~5ms
|
remote control commands from ~50ms to ~5ms
|
||||||
|
|
||||||
|
- Allow using the cwd of the original process for :option:`launch --cwd` (:iss:`5672`)
|
||||||
|
|
||||||
0.26.5 [2022-11-07]
|
0.26.5 [2022-11-07]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@ -93,14 +93,15 @@ opened window.
|
|||||||
|
|
||||||
|
|
||||||
--cwd
|
--cwd
|
||||||
completion=type:directory kwds:current,oldest,last_reported
|
completion=type:directory kwds:current,oldest,last_reported,root
|
||||||
The working directory for the newly launched child. Use the special value
|
The working directory for the newly launched child. Use the special value
|
||||||
:code:`current` to use the working directory of the currently active window.
|
:code:`current` to use the working directory of the currently active window.
|
||||||
The special value :code:`last_reported` uses the last working directory reported
|
The special value :code:`last_reported` uses the last working directory reported
|
||||||
by the shell (needs :ref:`shell_integration` to work). The special value
|
by the shell (needs :ref:`shell_integration` to work). The special value
|
||||||
:code:`oldest` works like :code:`current` but uses the working directory of the
|
:code:`oldest` works like :code:`current` but uses the working directory of the
|
||||||
oldest foreground process associated with the currently active window rather
|
oldest foreground process associated with the currently active window rather
|
||||||
than the newest foreground process.
|
than the newest foreground process. Finally, the special value :code:`root`
|
||||||
|
refers to the process that was originally started when the window was created.
|
||||||
|
|
||||||
|
|
||||||
--env
|
--env
|
||||||
@ -484,6 +485,9 @@ def launch(
|
|||||||
elif opts.cwd == 'oldest':
|
elif opts.cwd == 'oldest':
|
||||||
if active:
|
if active:
|
||||||
kw['cwd_from'] = CwdRequest(active, CwdRequestType.oldest)
|
kw['cwd_from'] = CwdRequest(active, CwdRequestType.oldest)
|
||||||
|
elif opts.cwd == 'root':
|
||||||
|
if active:
|
||||||
|
kw['cwd_from'] = CwdRequest(active, CwdRequestType.root)
|
||||||
else:
|
else:
|
||||||
kw['cwd'] = opts.cwd
|
kw['cwd'] = opts.cwd
|
||||||
if opts.location != 'default':
|
if opts.location != 'default':
|
||||||
|
|||||||
@ -69,6 +69,7 @@ class CwdRequestType(Enum):
|
|||||||
current: int = auto()
|
current: int = auto()
|
||||||
last_reported: int = auto()
|
last_reported: int = auto()
|
||||||
oldest: int = auto()
|
oldest: int = auto()
|
||||||
|
root: int = auto()
|
||||||
|
|
||||||
|
|
||||||
class CwdRequest:
|
class CwdRequest:
|
||||||
@ -92,6 +93,8 @@ class CwdRequest:
|
|||||||
reported_cwd = path_from_osc7_url(window.screen.last_reported_cwd) if window.screen.last_reported_cwd else ''
|
reported_cwd = path_from_osc7_url(window.screen.last_reported_cwd) if window.screen.last_reported_cwd else ''
|
||||||
if reported_cwd and not window.child_is_remote and (self.request_type is CwdRequestType.last_reported or window.at_prompt):
|
if reported_cwd and not window.child_is_remote and (self.request_type is CwdRequestType.last_reported or window.at_prompt):
|
||||||
return reported_cwd
|
return reported_cwd
|
||||||
|
if self.request_type is CwdRequestType.root:
|
||||||
|
return window.child.current_cwd or ''
|
||||||
return window.get_cwd_of_child(oldest=self.request_type is CwdRequestType.oldest) or ''
|
return window.get_cwd_of_child(oldest=self.request_type is CwdRequestType.oldest) or ''
|
||||||
|
|
||||||
def modify_argv_for_launch_with_cwd(self, argv: List[str]) -> str:
|
def modify_argv_for_launch_with_cwd(self, argv: List[str]) -> str:
|
||||||
@ -99,7 +102,7 @@ class CwdRequest:
|
|||||||
if not window:
|
if not window:
|
||||||
return ''
|
return ''
|
||||||
reported_cwd = path_from_osc7_url(window.screen.last_reported_cwd) if window.screen.last_reported_cwd else ''
|
reported_cwd = path_from_osc7_url(window.screen.last_reported_cwd) if window.screen.last_reported_cwd else ''
|
||||||
if reported_cwd:
|
if reported_cwd and (self.request_type is not CwdRequestType.root or window.root_in_foreground_processes):
|
||||||
# First check if we are running ssh kitten, and trying to open the configured login shell
|
# First check if we are running ssh kitten, and trying to open the configured login shell
|
||||||
if argv[0] == resolved_shell(get_options())[0]:
|
if argv[0] == resolved_shell(get_options())[0]:
|
||||||
ssh_kitten_cmdline = window.ssh_kitten_cmdline()
|
ssh_kitten_cmdline = window.ssh_kitten_cmdline()
|
||||||
@ -1389,6 +1392,14 @@ class Window:
|
|||||||
def cwd_of_child(self) -> Optional[str]:
|
def cwd_of_child(self) -> Optional[str]:
|
||||||
return self.get_cwd_of_child()
|
return self.get_cwd_of_child()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def root_in_foreground_processes(self) -> bool:
|
||||||
|
q = self.child.pid
|
||||||
|
for p in self.child.foreground_processes:
|
||||||
|
if p['pid'] == q:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def child_is_remote(self) -> bool:
|
def child_is_remote(self) -> bool:
|
||||||
for p in self.child.foreground_processes:
|
for p in self.child.foreground_processes:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user