From 70c2765a6e4409b5160e2c357be37f19e6f09040 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 Sep 2019 15:20:37 +0530 Subject: [PATCH] Allow reading session file from STDIN --- kitty/cli.py | 2 +- kitty/session.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kitty/cli.py b/kitty/cli.py index acbdc68a6..c2cc394fb 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -514,7 +514,7 @@ Detach from the controlling terminal, if any --session 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 diff --git a/kitty/session.py b/kitty/session.py index 57038286f..7a26bda37 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -3,14 +3,14 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import shlex +import sys from collections import namedtuple 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 .utils import log_error - WindowSizeOpts = namedtuple( '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): if args and args.session: - with open(args.session) as f: - yield from parse_session(f.read(), opts, getattr(args, 'title', None)) - return + if args.session == '-': + f = sys.stdin + 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': try: with open(default_session) as f: