From 1f63ff1d4109558545e6fb5047b0617e3916bca5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Sep 2018 10:49:20 +0530 Subject: [PATCH] Have the kitty --title flag apply to all windows created using kitty --session Fixes #921 --- docs/changelog.rst | 3 +++ kitty/cli.py | 4 +++- kitty/session.py | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index fa99e4c80..64427462e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -23,6 +23,9 @@ Changelog - Linux: Handle fonts that contain monochrome bitmaps (such as the Terminus TTF 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] ------------------------------ diff --git a/kitty/cli.py b/kitty/cli.py index 3fe201487..6b7bc7cce 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -474,7 +474,9 @@ Set the name part of the :italic:`WM_CLASS` property (defaults to using the valu --title -T 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 diff --git a/kitty/session.py b/kitty/session.py index 50ab8ddf4..03e62e5d8 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -24,9 +24,10 @@ class Tab: class Session: - def __init__(self): + def __init__(self, default_title=None): self.tabs = [] self.active_tab_idx = 0 + self.default_title = default_title def add_tab(self, opts, name=''): if self.tabs and not self.tabs[-1].windows: @@ -48,7 +49,7 @@ class Session: cmd = None from .tabs import SpecialWindow 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 def add_special_window(self, sw): @@ -76,8 +77,8 @@ def resolved_shell(opts): return ans -def parse_session(raw, opts): - ans = Session() +def parse_session(raw, opts, default_title=None): + ans = Session(default_title) ans.add_tab(opts) for line in raw.splitlines(): 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): if args and args.session: 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': try: 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: log_error('Failed to read from session file, ignoring: {}'.format(default_session)) else: - return parse_session(session_data, opts) + return parse_session(session_data, opts, getattr(args, 'title', None)) ans = Session() current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall' ans.add_tab(opts)