mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-18 14:34:52 +02:00
When running a kitten that modifies the kitty config file if no config file exists create a commented out default config file and then modify it
Fixes #7991
This commit is contained in:
@@ -93,6 +93,8 @@ Detailed list of changes
|
|||||||
|
|
||||||
- Fix background image flashing when closing a tab (:iss:`7999`)
|
- Fix background image flashing when closing a tab (:iss:`7999`)
|
||||||
|
|
||||||
|
- When running a kitten that modifies the kitty config file if no config file exists create a commented out default config file and then modify it (:iss:`7991`)
|
||||||
|
|
||||||
0.36.4 [2024-09-27]
|
0.36.4 [2024-09-27]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from kitty.cli import (
|
|||||||
)
|
)
|
||||||
from kitty.conf.generate import gen_go_code
|
from kitty.conf.generate import gen_go_code
|
||||||
from kitty.conf.types import Definition
|
from kitty.conf.types import Definition
|
||||||
|
from kitty.config import commented_out_default_config
|
||||||
from kitty.guess_mime_type import known_extensions, text_mimes
|
from kitty.guess_mime_type import known_extensions, text_mimes
|
||||||
from kitty.key_encoding import config_mod_map
|
from kitty.key_encoding import config_mod_map
|
||||||
from kitty.key_names import character_key_name_aliases, functional_key_name_aliases
|
from kitty.key_names import character_key_name_aliases, functional_key_name_aliases
|
||||||
@@ -626,6 +627,7 @@ var RefMap = map[string]string{serialize_go_dict(ref_map['ref'])}
|
|||||||
var DocTitleMap = map[string]string{serialize_go_dict(ref_map['doc'])}
|
var DocTitleMap = map[string]string{serialize_go_dict(ref_map['doc'])}
|
||||||
var AllowedShellIntegrationValues = []string{{ {str(sorted(allowed_shell_integration_values))[1:-1].replace("'", '"')} }}
|
var AllowedShellIntegrationValues = []string{{ {str(sorted(allowed_shell_integration_values))[1:-1].replace("'", '"')} }}
|
||||||
var QueryNames = []string{{ {query_names} }}
|
var QueryNames = []string{{ {query_names} }}
|
||||||
|
var CommentedOutDefaultConfig = "{serialize_as_go_string(commented_out_default_config())}"
|
||||||
var KittyConfigDefaults = struct {{
|
var KittyConfigDefaults = struct {{
|
||||||
Term, Shell_integration, Select_by_word_characters, Url_excluded_characters, Shell string
|
Term, Shell_integration, Select_by_word_characters, Url_excluded_characters, Shell string
|
||||||
Wheel_scroll_multiplier int
|
Wheel_scroll_multiplier int
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"kitty"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/process"
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
@@ -320,8 +321,15 @@ func (self Patcher) Patch(path, sentinel, content string, settings_to_comment_ou
|
|||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
add_at_top := ""
|
||||||
|
backup := true
|
||||||
if raw == nil {
|
if raw == nil {
|
||||||
raw = []byte{}
|
cc := kitty.CommentedOutDefaultConfig
|
||||||
|
if idx := strings.Index(cc, "\n\n"); idx > 0 {
|
||||||
|
add_at_top = cc[:idx+2]
|
||||||
|
raw = []byte(cc[idx+2:])
|
||||||
|
backup = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pat := utils.MustCompile(fmt.Sprintf(`(?m)^\s*(%s)\b`, strings.Join(settings_to_comment_out, "|")))
|
pat := utils.MustCompile(fmt.Sprintf(`(?m)^\s*(%s)\b`, strings.Join(settings_to_comment_out, "|")))
|
||||||
text := pat.ReplaceAllString(utils.UnsafeBytesToString(raw), `# $1`)
|
text := pat.ReplaceAllString(utils.UnsafeBytesToString(raw), `# $1`)
|
||||||
@@ -334,14 +342,21 @@ func (self Patcher) Patch(path, sentinel, content string, settings_to_comment_ou
|
|||||||
return addition
|
return addition
|
||||||
})
|
})
|
||||||
if !replaced {
|
if !replaced {
|
||||||
if text != "" {
|
if add_at_top != "" {
|
||||||
text += "\n\n"
|
ntext = add_at_top + addition
|
||||||
|
if text != "" {
|
||||||
|
ntext += "\n\n" + text
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if text != "" {
|
||||||
|
text += "\n\n"
|
||||||
|
}
|
||||||
|
ntext = text + addition
|
||||||
}
|
}
|
||||||
ntext = text + addition
|
|
||||||
}
|
}
|
||||||
nraw := utils.UnsafeStringToBytes(ntext)
|
nraw := utils.UnsafeStringToBytes(ntext)
|
||||||
if !bytes.Equal(raw, nraw) {
|
if !bytes.Equal(raw, nraw) {
|
||||||
if len(raw) > 0 && self.Write_backup {
|
if len(raw) > 0 && self.Write_backup && backup {
|
||||||
_ = os.WriteFile(backup_path+".bak", raw, self.Mode)
|
_ = os.WriteFile(backup_path+".bak", raw, self.Mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user