Allow getting the exe name of the active foreground process in the tab title template
This commit is contained in:
parent
a6dcbe9c1d
commit
dd4051bfd5
@ -444,6 +444,15 @@ class Child:
|
||||
return cwd_of_process(pid) or None
|
||||
return None
|
||||
|
||||
def get_foreground_exe(self, oldest: bool = False) -> Optional[str]:
|
||||
with suppress(Exception):
|
||||
pid = self.get_pid_for_cwd(oldest)
|
||||
if pid is not None:
|
||||
c = cmdline_of_pid(pid)
|
||||
if c:
|
||||
return c[0]
|
||||
return None
|
||||
|
||||
@property
|
||||
def foreground_cwd(self) -> Optional[str]:
|
||||
return self.get_foreground_cwd()
|
||||
|
||||
@ -1177,7 +1177,10 @@ use :code:`{sup.index}`. All data available is:
|
||||
The number of window groups (not counting overlay windows) in the tab.
|
||||
:code:`tab.active_wd`
|
||||
The working directory of the currently active window in the tab (expensive,
|
||||
requires syscall).
|
||||
requires syscall). Use :code:`active_oldest_wd` to get the directory of the oldest foreground process rather than the newest.
|
||||
:code:`tab.active_exe`
|
||||
The name of the executable running in the foreground of the currently active window in the tab (expensive,
|
||||
requires syscall). Use :code:`active_oldest_exe` for the oldest foreground process.
|
||||
:code:`max_title_length`
|
||||
The maximum title length available.
|
||||
|
||||
|
||||
@ -188,6 +188,21 @@ class TabAccessor:
|
||||
tab = get_boss().tab_for_id(self.tab_id)
|
||||
return (tab.get_cwd_of_active_window() if tab else '') or ''
|
||||
|
||||
@property
|
||||
def active_oldest_wd(self) -> str:
|
||||
tab = get_boss().tab_for_id(self.tab_id)
|
||||
return (tab.get_cwd_of_active_window(oldest=True) if tab else '') or ''
|
||||
|
||||
@property
|
||||
def active_exe(self) -> str:
|
||||
tab = get_boss().tab_for_id(self.tab_id)
|
||||
return os.path.basename((tab.get_exe_of_active_window() if tab else '') or '')
|
||||
|
||||
@property
|
||||
def active_oldest_exe(self) -> str:
|
||||
tab = get_boss().tab_for_id(self.tab_id)
|
||||
return os.path.basename((tab.get_exe_of_active_window(oldest=True) if tab else '') or '')
|
||||
|
||||
|
||||
safe_builtins = {
|
||||
'max': max, 'min': min, 'str': str, 'repr': repr, 'abs': abs, 'len': len, 're': re,
|
||||
|
||||
@ -235,6 +235,10 @@ class Tab: # {{{
|
||||
w = self.active_window
|
||||
return w.get_cwd_of_child(oldest) if w else None
|
||||
|
||||
def get_exe_of_active_window(self, oldest: bool = False) -> Optional[str]:
|
||||
w = self.active_window
|
||||
return w.get_exe_of_child(oldest) if w else None
|
||||
|
||||
def set_title(self, title: str) -> None:
|
||||
self.name = title or ''
|
||||
self.mark_tab_bar_dirty()
|
||||
|
||||
@ -1391,6 +1391,9 @@ class Window:
|
||||
def get_cwd_of_root_child(self) -> Optional[str]:
|
||||
return self.child.current_cwd
|
||||
|
||||
def get_exe_of_child(self, oldest: bool = False) -> str:
|
||||
return self.child.get_foreground_exe(oldest) or self.child.argv[0]
|
||||
|
||||
@property
|
||||
def cwd_of_child(self) -> Optional[str]:
|
||||
return self.get_cwd_of_child()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user