diff --git a/docs/changelog.rst b/docs/changelog.rst index 45f6e5fa6..1ae250332 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/themes/collection.py b/kittens/themes/collection.py index e75762313..2b8c5935e 100644 --- a/kittens/themes/collection.py +++ b/kittens/themes/collection.py @@ -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() diff --git a/kittens/themes/main.py b/kittens/themes/main.py index e53e76b0e..48024bf1c 100644 --- a/kittens/themes/main.py +++ b/kittens/themes/main.py @@ -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: