Nicer fix for showing cwd in tab titles
This commit is contained in:
parent
f6a1eb19d7
commit
352c07987b
@ -84,6 +84,9 @@ Detailed list of changes
|
|||||||
|
|
||||||
- Expand ~ in paths configured in :opt:`editor` and :opt:`exe_search_path` (:disc:`5298`)
|
- Expand ~ in paths configured in :opt:`editor` and :opt:`exe_search_path` (:disc:`5298`)
|
||||||
|
|
||||||
|
- Allow showing the working directory of the active window in tab titles
|
||||||
|
(:pull:`5314`)
|
||||||
|
|
||||||
|
|
||||||
0.25.2 [2022-06-07]
|
0.25.2 [2022-06-07]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@ -1166,7 +1166,8 @@ mapped for :code:`goto_tab N`. If you prefer to see the index as a superscript,
|
|||||||
use :code:`{sup.index}`. In addition you can use :code:`{layout_name}` for the
|
use :code:`{sup.index}`. In addition you can use :code:`{layout_name}` for the
|
||||||
current layout name, :code:`{num_windows}` for the number of windows in the tab,
|
current layout name, :code:`{num_windows}` for the number of windows in the tab,
|
||||||
:code:`{num_window_groups}` for the number of window groups (not counting
|
:code:`{num_window_groups}` for the number of window groups (not counting
|
||||||
overlay windows) in the tab, and {cwd} for current working directory.
|
overlay windows) in the tab, and :code:`{tab.active_wd}` for the working directory
|
||||||
|
of the active_window.
|
||||||
Note that formatting is done by Python's string formatting machinery, so you can
|
Note that formatting is done by Python's string formatting machinery, so you can
|
||||||
use, for instance, :code:`{layout_name[:2].upper()}` to show only the first two
|
use, for instance, :code:`{layout_name[:2].upper()}` to show only the first two
|
||||||
letters of the layout name, upper-cased. If you want to style the text, you can
|
letters of the layout name, upper-cased. If you want to style the text, you can
|
||||||
|
|||||||
@ -178,28 +178,14 @@ def template_has_field(template: str, field: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class TabCWD:
|
|
||||||
|
|
||||||
def __init__(self, tab_ref: 'ReferenceType[Tab]'):
|
|
||||||
self.tab_ref = tab_ref
|
|
||||||
self.saved_val: Optional[str] = None
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
if self.saved_val is None:
|
|
||||||
tab = self.tab_ref()
|
|
||||||
self.saved_val = (tab.get_cwd_of_active_window() or '') if tab else ''
|
|
||||||
return self.saved_val
|
|
||||||
|
|
||||||
|
|
||||||
def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) -> None:
|
def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) -> None:
|
||||||
tcwd = TabCWD(tab.tab_ref)
|
|
||||||
data = {
|
data = {
|
||||||
'index': index,
|
'index': index,
|
||||||
'layout_name': tab.layout_name,
|
'layout_name': tab.layout_name,
|
||||||
'num_windows': tab.num_windows,
|
'num_windows': tab.num_windows,
|
||||||
'num_window_groups': tab.num_window_groups,
|
'num_window_groups': tab.num_window_groups,
|
||||||
'title': tab.title,
|
'title': tab.title,
|
||||||
'cwd': tcwd,
|
'tab': tab.tab_ref(),
|
||||||
}
|
}
|
||||||
ColorFormatter.draw_data = draw_data
|
ColorFormatter.draw_data = draw_data
|
||||||
ColorFormatter.tab_data = tab
|
ColorFormatter.tab_data = tab
|
||||||
@ -209,7 +195,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int)
|
|||||||
'num_windows': tab.num_windows,
|
'num_windows': tab.num_windows,
|
||||||
'num_window_groups': tab.num_window_groups,
|
'num_window_groups': tab.num_window_groups,
|
||||||
'title': tab.title,
|
'title': tab.title,
|
||||||
'cwd': tcwd,
|
'tab': tab.tab_ref(),
|
||||||
'fmt': Formatter,
|
'fmt': Formatter,
|
||||||
'sup': SupSub(data),
|
'sup': SupSub(data),
|
||||||
'sub': SupSub(data, True),
|
'sub': SupSub(data, True),
|
||||||
|
|||||||
@ -234,6 +234,10 @@ class Tab: # {{{
|
|||||||
w = self.active_window
|
w = self.active_window
|
||||||
return w.get_cwd_of_child(oldest) if w else None
|
return w.get_cwd_of_child(oldest) if w else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def active_wd(self) -> str:
|
||||||
|
return self.get_cwd_of_active_window() or ''
|
||||||
|
|
||||||
def set_title(self, title: str) -> None:
|
def set_title(self, title: str) -> None:
|
||||||
self.name = title or ''
|
self.name = title or ''
|
||||||
self.mark_tab_bar_dirty()
|
self.mark_tab_bar_dirty()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user