mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
themes kitten: Allow writing to a different file than kitty.conf
This commit is contained in:
@@ -139,6 +139,8 @@ Detailed list of changes
|
|||||||
- Fix clicking in a window to focus it and typing immediately sometimes having
|
- Fix clicking in a window to focus it and typing immediately sometimes having
|
||||||
unexpected effects if at a shell prompt (:iss:`4128`)
|
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]
|
0.24.1 [2022-01-06]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -522,10 +522,10 @@ class Theme:
|
|||||||
def save_in_dir(self, dirpath: str) -> None:
|
def save_in_dir(self, dirpath: str) -> None:
|
||||||
atomic_save(self.raw.encode('utf-8'), os.path.join(dirpath, f'{self.name}.conf'))
|
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)
|
os.makedirs(confdir, exist_ok=True)
|
||||||
atomic_save(self.raw.encode('utf-8'), os.path.join(confdir, 'current-theme.conf'))
|
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:
|
try:
|
||||||
with open(confpath) as f:
|
with open(confpath) as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ class ThemesHandler(Handler):
|
|||||||
def draw_accepting_screen(self) -> None:
|
def draw_accepting_screen(self) -> None:
|
||||||
name = self.themes_list.current_theme.name
|
name = self.themes_list.current_theme.name
|
||||||
name = styled(name, bold=True, fg="green")
|
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:
|
def ac(x: str) -> str:
|
||||||
return styled(x, fg='red')
|
return styled(x, fg='red')
|
||||||
@@ -465,7 +465,7 @@ class ThemesHandler(Handler):
|
|||||||
self.quit_on_next_key_release = 0
|
self.quit_on_next_key_release = 0
|
||||||
return
|
return
|
||||||
if key_event.matches_text('m'):
|
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.update_recent()
|
||||||
self.quit_on_next_key_release = 0
|
self.quit_on_next_key_release = 0
|
||||||
return
|
return
|
||||||
@@ -536,6 +536,13 @@ type=bool-set
|
|||||||
default=false
|
default=false
|
||||||
When running non-interactively, dump the specified theme to STDOUT
|
When running non-interactively, dump the specified theme to STDOUT
|
||||||
instead of changing kitty.conf.
|
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
|
'''.format
|
||||||
|
|
||||||
|
|
||||||
@@ -559,7 +566,7 @@ def non_interactive(cli_opts: ThemesCLIOptions, theme_name: str) -> None:
|
|||||||
if cli_opts.dump_theme:
|
if cli_opts.dump_theme:
|
||||||
print(theme.raw)
|
print(theme.raw)
|
||||||
return
|
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:
|
def main(args: List[str]) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user