Have the kitty --title flag apply to all windows created using kitty --session

Fixes #921
This commit is contained in:
Kovid Goyal 2018-09-09 10:49:20 +05:30
parent 49d8f4689f
commit 1f63ff1d41
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 7 deletions

View File

@ -23,6 +23,9 @@ Changelog
- Linux: Handle fonts that contain monochrome bitmaps (such as the Terminus TTF - Linux: Handle fonts that contain monochrome bitmaps (such as the Terminus TTF
font) (:pull:`934`) font) (:pull:`934`)
- Have the :option:`kitty --title` flag apply to all windows created
using :option:`kitty --session` (:iss:`921`)
0.12.1 [2018-09-08] 0.12.1 [2018-09-08]
------------------------------ ------------------------------

View File

@ -474,7 +474,9 @@ Set the name part of the :italic:`WM_CLASS` property (defaults to using the valu
--title -T --title -T
Set the window title. This will override any title set by the program running inside kitty. So Set the window title. This will override any title set by the program running inside kitty. So
only use this if you are running a program that does not set titles. only use this if you are running a program that does not set titles. If combined
with :option:`{appname} --session` the title will be used for all windows created by the
session, that do not set their own titles.
--config -c --config -c

View File

@ -24,9 +24,10 @@ class Tab:
class Session: class Session:
def __init__(self): def __init__(self, default_title=None):
self.tabs = [] self.tabs = []
self.active_tab_idx = 0 self.active_tab_idx = 0
self.default_title = default_title
def add_tab(self, opts, name=''): def add_tab(self, opts, name=''):
if self.tabs and not self.tabs[-1].windows: if self.tabs and not self.tabs[-1].windows:
@ -48,7 +49,7 @@ class Session:
cmd = None cmd = None
from .tabs import SpecialWindow from .tabs import SpecialWindow
t = self.tabs[-1] t = self.tabs[-1]
t.windows.append(SpecialWindow(cmd, cwd=t.cwd, override_title=t.next_title)) t.windows.append(SpecialWindow(cmd, cwd=t.cwd, override_title=t.next_title or self.default_title))
t.next_title = None t.next_title = None
def add_special_window(self, sw): def add_special_window(self, sw):
@ -76,8 +77,8 @@ def resolved_shell(opts):
return ans return ans
def parse_session(raw, opts): def parse_session(raw, opts, default_title=None):
ans = Session() ans = Session(default_title)
ans.add_tab(opts) ans.add_tab(opts)
for line in raw.splitlines(): for line in raw.splitlines():
line = line.strip() line = line.strip()
@ -109,7 +110,7 @@ def parse_session(raw, opts):
def create_session(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False, default_session=None): def create_session(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False, default_session=None):
if args and args.session: if args and args.session:
with open(args.session) as f: with open(args.session) as f:
return parse_session(f.read(), opts) return parse_session(f.read(), opts, getattr(args, 'title', None))
if default_session and default_session != 'none': if default_session and default_session != 'none':
try: try:
with open(default_session) as f: with open(default_session) as f:
@ -117,7 +118,7 @@ def create_session(opts, args=None, special_window=None, cwd_from=None, respect_
except EnvironmentError: except EnvironmentError:
log_error('Failed to read from session file, ignoring: {}'.format(default_session)) log_error('Failed to read from session file, ignoring: {}'.format(default_session))
else: else:
return parse_session(session_data, opts) return parse_session(session_data, opts, getattr(args, 'title', None))
ans = Session() ans = Session()
current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall' current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall'
ans.add_tab(opts) ans.add_tab(opts)