diff --git a/kitty/boss.py b/kitty/boss.py index 4cbfaa3d8..ffda0dae2 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -96,7 +96,7 @@ class Boss: ) set_boss(self) self.opts, self.args = opts, args - startup_session = create_session(opts, args) + startup_session = create_session(opts, args, default_session=opts.startup_session) self.keymap = self.opts.keymap.copy() if new_os_window_trigger is not None: self.keymap.pop(new_os_window_trigger, None) diff --git a/kitty/config_data.py b/kitty/config_data.py index 5f0668800..6522a6b01 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -616,6 +616,12 @@ opening new windows, closing windows, reading the content of windows, etc. Note that this even works over ssh connections. ''')) +o('startup_session', 'none', option_type=lambda x: (None if x.lower() == 'none' else x), long_text=_(''' +Path to a session file to use for all kitty instances. Can be overridden +by using the :option:`--startup-session` command line option for individual +instances. See :ref:`sessions` in the kitty documentation for details. +''')) + o('clipboard_control', 'write-clipboard write-primary', option_type=lambda x: frozenset(x.lower().split()), long_text=_(''' Allow programs running in kitty to read and write from the clipboard. You can control exactly which actions are allowed. The set of possible actions is: diff --git a/kitty/session.py b/kitty/session.py index b4e6a8d49..4ed9656c6 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -7,6 +7,7 @@ import shlex from .config_data import to_layout_names from .constants import shell_path from .layout import all_layouts +from .utils import log_error class Tab: @@ -105,10 +106,18 @@ def parse_session(raw, opts): return ans -def create_session(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False): +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) + if default_session and default_session != 'none': + try: + with open(default_session) as f: + session_data = f.read() + except EnvironmentError: + log_error('Failed to read from session file, ignoring: {}'.format(default_session)) + else: + return parse_session(session_data, opts) ans = Session() current_layout = opts.enabled_layouts[0] if opts.enabled_layouts else 'tall' ans.add_tab(opts)