diff --git a/README.md b/README.md index 88e3c94bd..9dd58a8a8 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,10 @@ launch zsh launch vim launch irssi --profile x -# Create a new tab -new_tab +# Create a new tab (the part after new_tab is the optional tab name which will +# be displayed in the tab bar, if ommitted, the title of the active window will +# be used instead) +new_tab my tab cd ~/somewhere # Set the layouts allowed in this tab enabled_layouts tall, stack diff --git a/kitty/session.py b/kitty/session.py index 861d0c94e..96df6254e 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -11,8 +11,9 @@ from .layout import all_layouts class Tab: - def __init__(self, opts): + def __init__(self, opts, name): self.windows = [] + self.name = name.strip() self.active_window_idx = 0 self.enabled_layouts = opts.enabled_layouts self.layout = (self.enabled_layouts or ['tall'])[0] @@ -25,8 +26,10 @@ class Session: self.tabs = [] self.active_tab_idx = 0 - def add_tab(self, opts): - self.tabs.append(Tab(opts)) + def add_tab(self, opts, name=''): + if self.tabs and not self.tabs[-1].windows: + del self.tabs[-1] + self.tabs.append(Tab(opts, name)) def set_layout(self, val): if val not in all_layouts: @@ -60,7 +63,7 @@ def parse_session(raw, opts): cmd, rest = line.partition(' ')[::2] cmd, rest = cmd.strip(), rest.strip() if cmd == 'new_tab': - ans.add_tab(opts) + ans.add_tab(opts, rest) elif cmd == 'layout': ans.set_layout(rest) elif cmd == 'launch': diff --git a/kitty/tabs.py b/kitty/tabs.py index cd1d1a18f..e111f4336 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -21,6 +21,7 @@ class Tab: def __init__(self, opts, args, on_title_change, session_tab=None): self.opts, self.args = opts, args + self.name = getattr(session_tab, 'name', '') self.on_title_change = on_title_change self.enabled_layouts = list((session_tab or opts).enabled_layouts) self.borders = Borders(opts) @@ -225,7 +226,7 @@ class TabManager: at = self.active_tab for t in self.tabs: - title = (t.title or appname) + ' ' + title = (t.name or t.title or appname) + ' ' s.cursor.bg = self.active_bg if t is at else 0 s.cursor.fg = self.active_fg if t is at else 0 s.cursor.bold = t is at