choose-fonts kitten: allow specifying the name of the conf file to edit

Fixes #7926
This commit is contained in:
Kovid Goyal
2024-09-29 20:50:00 +05:30
parent af83d855de
commit 71d49b5328
2 changed files with 21 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ func (self *final_pane) draw_screen() (err error) {
"",
"What would you like to do?",
"",
fmt.Sprintf("%s to modify %s and use the new fonts", h("Enter"), s("italic", `kitty.conf`)),
fmt.Sprintf("%s to modify %s and use the new fonts", h("Enter"), s("italic", self.handler.opts.Config_file_name)),
"",
fmt.Sprintf("%s to abort and return to font selection", h("Esc")),
"",
@@ -78,7 +78,12 @@ func (self *final_pane) on_key_event(event *loop.KeyEvent) (err error) {
if event.MatchesPressOrRepeat("enter") {
event.Handled = true
patcher := config.Patcher{Write_backup: true}
path := filepath.Join(utils.ConfigDir(), "kitty.conf")
path := ""
if filepath.IsAbs(self.handler.opts.Config_file_name) {
path = self.handler.opts.Config_file_name
} else {
path = filepath.Join(utils.ConfigDir(), self.handler.opts.Config_file_name)
}
updated, err := patcher.Patch(path, "KITTY_FONTS", self.settings.serialized(), "font_family", "bold_font", "italic_font", "bold_italic_font")
if err != nil {
return err

View File

@@ -68,7 +68,8 @@ func main(opts *Options) (rc int, err error) {
}
type Options struct {
Reload_in string
Reload_in string
Config_file_name string
}
func EntryPoint(root *cli.Command) {
@@ -93,6 +94,18 @@ func EntryPoint(root *cli.Command) {
running in to reload its config, after making changes. Use this option to
instead either not reload the config at all or in all running kitty instances.`,
})
ans.Add(cli.OptionSpec{
Name: "--config-file-name",
Dest: "Config_file_name",
Type: "str",
Default: "kitty.conf",
Help: `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. This is most useful if you add include
fonts.conf to your kitty.conf and then have the kitten operate only on
fonts.conf, allowing kitty.conf to remain unchanged.`,
})
clone := root.AddClone(ans.Group, ans)
clone.Hidden = false
clone.Name = "choose_fonts"