Allow reading session file from STDIN

This commit is contained in:
Kovid Goyal 2019-09-08 15:20:37 +05:30
parent 3618f4d642
commit 70c2765a6e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 6 deletions

View File

@ -514,7 +514,7 @@ Detach from the controlling terminal, if any
--session --session
Path to a file containing the startup :italic:`session` (tabs, windows, layout, programs). Path to a file containing the startup :italic:`session` (tabs, windows, layout, programs).
See the README file for details and an example. Use - to read from STDIN. See the README file for details and an example.
--hold --hold

View File

@ -3,14 +3,14 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import shlex import shlex
import sys
from collections import namedtuple from collections import namedtuple
from .config_data import to_layout_names from .config_data import to_layout_names
from .constants import shell_path, kitty_exe from .constants import kitty_exe, shell_path
from .layout import all_layouts from .layout import all_layouts
from .utils import log_error from .utils import log_error
WindowSizeOpts = namedtuple( WindowSizeOpts = namedtuple(
'WindowSizeOpts', 'initial_window_width initial_window_height window_margin_width window_padding_width remember_window_size') 'WindowSizeOpts', 'initial_window_width initial_window_height window_margin_width window_padding_width remember_window_size')
@ -131,9 +131,14 @@ def parse_session(raw, opts, default_title=None):
def create_sessions(opts, args=None, special_window=None, cwd_from=None, respect_cwd=False, default_session=None): def create_sessions(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: if args.session == '-':
yield from parse_session(f.read(), opts, getattr(args, 'title', None)) f = sys.stdin
return else:
f = open(args.session)
with f:
session_data = f.read()
yield from parse_session(session_data, opts, getattr(args, 'title', None))
return
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: