Add an option to kitty.conf to specify a default startup session

Fixes #641
This commit is contained in:
Kovid Goyal 2018-06-16 08:14:11 +05:30
parent 26f50a451e
commit 12cbcf1c17
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 2 deletions

View File

@ -96,7 +96,7 @@ class Boss:
) )
set_boss(self) set_boss(self)
self.opts, self.args = opts, args 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() self.keymap = self.opts.keymap.copy()
if new_os_window_trigger is not None: if new_os_window_trigger is not None:
self.keymap.pop(new_os_window_trigger, None) self.keymap.pop(new_os_window_trigger, None)

View File

@ -616,6 +616,12 @@ opening new windows, closing windows, reading the content of windows, etc.
Note that this even works over ssh connections. 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=_(''' 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 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: control exactly which actions are allowed. The set of possible actions is:

View File

@ -7,6 +7,7 @@ import shlex
from .config_data import to_layout_names from .config_data import to_layout_names
from .constants import shell_path from .constants import shell_path
from .layout import all_layouts from .layout import all_layouts
from .utils import log_error
class Tab: class Tab:
@ -105,10 +106,18 @@ def parse_session(raw, opts):
return ans 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: 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)
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() 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)