save_as_session: when the filename input by the user has no extension, automatically add the `.kitty-session` extension

Fixes #9919
This commit is contained in:
Kovid Goyal 2026-04-25 14:29:44 +05:30
parent a5940b4eb1
commit 851ec96979
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 2 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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))