Session file: Allow setting the title for windows

This commit is contained in:
Kovid Goyal 2018-01-08 12:47:47 +05:30
parent c551384369
commit 85a3da057f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 1 deletions

View File

@ -291,6 +291,8 @@ cd ~
# Create a window and run the specified command in it
launch zsh
launch vim
# Set the title for the next window
title Chat with x
launch irssi --profile x
# Create a new tab (the part after new_tab is the optional tab name which will

View File

@ -18,6 +18,7 @@ def __init__(self, opts, name):
self.enabled_layouts = opts.enabled_layouts
self.layout = (self.enabled_layouts or ['tall'])[0]
self.cwd = None
self.next_title = None
class Session:
@ -31,6 +32,9 @@ def add_tab(self, opts, name=''):
del self.tabs[-1]
self.tabs.append(Tab(opts, name))
def set_next_title(self, title):
self.tabs[-1].next_title = title.strip()
def set_layout(self, val):
if val not in all_layouts:
raise ValueError('{} is not a valid layout'.format(val))
@ -42,7 +46,9 @@ def add_window(self, cmd):
else:
cmd = None
from .tabs import SpecialWindow
self.tabs[-1].windows.append(SpecialWindow(cmd, cwd=self.tabs[-1].cwd))
t = self.tabs[-1]
t.windows.append(SpecialWindow(cmd, cwd=t.cwd, override_title=t.next_title))
t.next_title = None
def add_special_window(self, sw):
self.tabs[-1].windows.append(sw)
@ -78,6 +84,8 @@ def parse_session(raw, opts):
ans.set_enabled_layouts(rest)
elif cmd == 'cd':
ans.set_cwd(rest)
elif cmd == 'title':
ans.set_next_title(rest)
else:
raise ValueError('Unknown command in session file: {}'.format(cmd))
for t in ans.tabs: