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:
Kovid Goyal
2019-01-03 13:29:52 +05:30
parent c4aeb1adba
commit 718f7e77a1
4 changed files with 31 additions and 10 deletions

View File

@@ -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