Allow using --session=none to override startup_session

Fixes #6131
This commit is contained in:
Kovid Goyal
2023-03-25 10:43:38 +05:30
parent f046884f23
commit 5ff1dadf0d
5 changed files with 24 additions and 14 deletions
+5 -2
View File
@@ -763,8 +763,11 @@ class Boss:
args.args = rest
opts = create_opts(args)
if data['session_data']:
from .session import PreReadSession
args.session = PreReadSession(data['session_data'], data['environ'])
if data['session_data'] == 'none':
args.session = 'none'
else:
from .session import PreReadSession
args.session = PreReadSession(data['session_data'], data['environ'])
else:
args.session = ''
if not os.path.isabs(args.directory):
+2
View File
@@ -898,6 +898,8 @@ Path to a file containing the startup :italic:`session` (tabs, windows, layout,
programs). Use - to read from STDIN. See the :file:`README` file for details and
an example. Environment variables in the file name are expanded,
relative paths are resolved relative to the kitty configuration directory.
The special value :code:`none` means no session will be used, even if
the :opt:`startup_session` option has been specified in kitty.conf.
--hold
+2
View File
@@ -85,6 +85,8 @@ def talk_to_instance(args: CLIOptions) -> None:
session_data = ''
if args.session == '-':
session_data = sys.stdin.read()
elif args.session == 'none':
session_data = 'none'
elif args.session:
with open(args.session) as f:
session_data = f.read()
+1 -1
View File
@@ -2938,7 +2938,7 @@ opt('startup_session', 'none',
option_type='config_or_absolute_path',
long_text='''
Path to a session file to use for all kitty instances. Can be overridden by
using the :option:`kitty --session` command line option for individual
using the :option:`kitty --session` :code:`=none` command line option for individual
instances. See :ref:`sessions` in the kitty documentation for details. Note that
relative paths are interpreted with respect to the kitty config directory.
Environment variables in the path are expanded. Changing this option by
+14 -11
View File
@@ -205,19 +205,22 @@ def create_sessions(
default_session: Optional[str] = None,
) -> Iterator[Session]:
if args and args.session:
environ: Optional[Mapping[str, str]] = None
if isinstance(args.session, PreReadSession):
session_data = '' + str(args.session)
environ = args.session.associated_environ # type: ignore
if args.session == "none":
default_session = "none"
else:
if args.session == '-':
f = sys.stdin
environ: Optional[Mapping[str, str]] = None
if isinstance(args.session, PreReadSession):
session_data = '' + str(args.session)
environ = args.session.associated_environ # type: ignore
else:
f = open(resolve_custom_file(args.session))
with f:
session_data = f.read()
yield from parse_session(session_data, opts, environ=environ)
return
if args.session == '-':
f = sys.stdin
else:
f = open(resolve_custom_file(args.session))
with f:
session_data = f.read()
yield from parse_session(session_data, opts, environ=environ)
return
if default_session and default_session != 'none':
try:
with open(default_session) as f: