diff --git a/docs/changelog.rst b/docs/changelog.rst index fb365b540..e3fe3aabc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -258,6 +258,8 @@ Detailed list of changes - macOS: Fix args passed via ``open --args`` being ignored when :file:`macos-launch-services-cmdline` is present (:iss:`9910`) +- :ac:`save_as_session`: when the filename input by the user has no extension, automatically add the ``.kitty-session`` extension (:pull:`9919`) + 0.46.2 [2026-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/session.py b/kitty/session.py index c2986303a..e54a412d3 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -691,7 +691,7 @@ co-located with their project directories. ''' -def save_as_session_part2(boss: BossType, opts: SaveAsSessionOptions, path: str) -> None: +def save_as_session_part2(boss: BossType, opts: SaveAsSessionOptions, path: str, path_input_by_user: bool = False) -> None: if not path: return from .config import atomic_save @@ -699,6 +699,8 @@ def save_as_session_part2(boss: BossType, opts: SaveAsSessionOptions, path: str) base_dir = os.path.abspath(os.path.expanduser(opts.base_dir)) path = os.path.join(base_dir, path) path = os.path.abspath(os.path.expanduser(path)) + if path_input_by_user and '.' not in os.path.basename(path): + path += '.kitty-session' session = '\n'.join(boss.serialize_state_as_session(path, opts)) os.makedirs(os.path.dirname(path), exist_ok=True) atomic_save(session.encode(), path) @@ -732,4 +734,4 @@ def save_as_session(boss: BossType, cmdline: Sequence[str]) -> None: else: boss.get_save_filepath(_( 'Enter the path at which to save the session, usually session files are given the .kitty-session file extension'), - partial(save_as_session_part2, boss, opts)) + partial(save_as_session_part2, boss, opts, path_input_by_user=True))