themes kitten: Allow writing to a different file than kitty.conf

This commit is contained in:
Kovid Goyal 2022-01-27 20:24:39 +05:30
parent 4f6c16984a
commit 5cdff7d6d0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 5 deletions

View File

@ -139,6 +139,8 @@ Detailed list of changes
- Fix clicking in a window to focus it and typing immediately sometimes having
unexpected effects if at a shell prompt (:iss:`4128`)
- themes kitten: Allow writing to a different file than :file:`kitty.conf`.
0.24.1 [2022-01-06]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -522,10 +522,10 @@ class Theme:
def save_in_dir(self, dirpath: str) -> None:
atomic_save(self.raw.encode('utf-8'), os.path.join(dirpath, f'{self.name}.conf'))
def save_in_conf(self, confdir: str, reload_in: str) -> None:
def save_in_conf(self, confdir: str, reload_in: str, config_file_name: str = 'kitty.conf') -> None:
os.makedirs(confdir, exist_ok=True)
atomic_save(self.raw.encode('utf-8'), os.path.join(confdir, 'current-theme.conf'))
confpath = os.path.realpath(os.path.join(confdir, 'kitty.conf'))
confpath = os.path.realpath(os.path.join(confdir, config_file_name))
try:
with open(confpath) as f:
raw = f.read()

View File

@ -433,7 +433,7 @@ class ThemesHandler(Handler):
def draw_accepting_screen(self) -> None:
name = self.themes_list.current_theme.name
name = styled(name, bold=True, fg="green")
kc = styled('kitty.conf', italic=True)
kc = styled(self.cli_opts.config_file_name, italic=True)
def ac(x: str) -> str:
return styled(x, fg='red')
@ -465,7 +465,7 @@ class ThemesHandler(Handler):
self.quit_on_next_key_release = 0
return
if key_event.matches_text('m'):
self.themes_list.current_theme.save_in_conf(config_dir, self.cli_opts.reload_in)
self.themes_list.current_theme.save_in_conf(config_dir, self.cli_opts.reload_in, self.cli_opts.config_file_name)
self.update_recent()
self.quit_on_next_key_release = 0
return
@ -536,6 +536,13 @@ type=bool-set
default=false
When running non-interactively, dump the specified theme to STDOUT
instead of changing kitty.conf.
--config-file-name
default=kitty.conf
The name or path to the config file to edit. Relative paths are interpreted
with respect to the kitty config directory. By default the kitty config file,
kitty.conf is edited.
'''.format
@ -559,7 +566,7 @@ def non_interactive(cli_opts: ThemesCLIOptions, theme_name: str) -> None:
if cli_opts.dump_theme:
print(theme.raw)
return
theme.save_in_conf(config_dir, cli_opts.reload_in)
theme.save_in_conf(config_dir, cli_opts.reload_in, cli_opts.config_file_name)
def main(args: List[str]) -> None: