mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 21:45:03 +02:00
Use the current working directory of the foreground process for the *_with_cwd actions that open a new window with the current working directory.
This commit is contained in:
@@ -205,6 +205,10 @@ class Child:
|
||||
ans['cmdline'] = cmdline_of_process(pid)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
ans['cwd'] = cwd_of_process(pid) or None
|
||||
except Exception:
|
||||
pass
|
||||
return ans
|
||||
|
||||
return list(map(process_desc, foreground_processes))
|
||||
@@ -231,3 +235,21 @@ class Child:
|
||||
return cwd_of_process(self.pid)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@property
|
||||
def pid_for_cwd(self):
|
||||
try:
|
||||
pgrp = os.tcgetpgrp(self.child_fd)
|
||||
foreground_processes = processes_in_group(pgrp) if pgrp >= 0 else []
|
||||
if len(foreground_processes) == 1:
|
||||
return foreground_processes[0]
|
||||
except Exception:
|
||||
pass
|
||||
return self.pid
|
||||
|
||||
@property
|
||||
def foreground_cwd(self):
|
||||
try:
|
||||
return cwd_of_process(self.pid_for_cwd) or None
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user