mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 06:54:58 +02:00
Implement using effective kitty config options for kittens
Also centralise reading of kitty options
This commit is contained in:
@@ -400,3 +400,19 @@ func ReloadConfigInKitty(in_parent_only bool) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadKittyConfig(line_handler func(key, val string) error) error {
|
||||
kitty_conf_path := ""
|
||||
kp := os.Getenv("KITTY_PID")
|
||||
if _, err := strconv.Atoi(kp); err == nil {
|
||||
effective_config_path := filepath.Join(utils.CacheDir(), "effective-config", kp)
|
||||
if unix.Access(effective_config_path, unix.R_OK) == nil {
|
||||
kitty_conf_path = effective_config_path
|
||||
}
|
||||
}
|
||||
if kitty_conf_path == "" {
|
||||
kitty_conf_path = filepath.Join(utils.ConfigDir(), "kitty.conf")
|
||||
}
|
||||
cp := ConfigParser{LineHandler: line_handler}
|
||||
return cp.ParseFiles(kitty_conf_path)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"kitty"
|
||||
@@ -268,9 +267,8 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) {
|
||||
if len(style) == 0 {
|
||||
if !m.default_url_style.loaded {
|
||||
m.default_url_style.loaded = true
|
||||
conf := filepath.Join(utils.ConfigDir(), "kitty.conf")
|
||||
color, style := kitty.DefaultUrlColor, kitty.DefaultUrlStyle
|
||||
cp := config.ConfigParser{LineHandler: func(key, val string) error {
|
||||
line_handler := func(key, val string) error {
|
||||
switch key {
|
||||
case "url_color":
|
||||
color = val
|
||||
@@ -278,9 +276,8 @@ func (m *MouseState) ApplyHoverStyles(lp *loop.Loop, style ...string) {
|
||||
style = val
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
_ = cp.ParseFiles(conf) // ignore errors and use defaults
|
||||
config.ReadKittyConfig(line_handler)
|
||||
if style != "none" && style != "" {
|
||||
m.default_url_style.value = fmt.Sprintf("u=%s uc=%s", style, color)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type KittyOpts struct {
|
||||
Shell, Shell_integration string
|
||||
}
|
||||
|
||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
||||
func read_relevant_kitty_opts() KittyOpts {
|
||||
ans := KittyOpts{Shell: kitty.KittyConfigDefaults.Shell, Shell_integration: kitty.KittyConfigDefaults.Shell_integration}
|
||||
handle_line := func(key, val string) error {
|
||||
switch key {
|
||||
@@ -41,8 +41,7 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
cp := config.ConfigParser{LineHandler: handle_line}
|
||||
_ = cp.ParseFiles(path)
|
||||
config.ReadKittyConfig(handle_line)
|
||||
if ans.Shell == "" {
|
||||
ans.Shell = kitty.KittyConfigDefaults.Shell
|
||||
}
|
||||
@@ -63,7 +62,7 @@ func get_effective_ksi_env_var(x string) string {
|
||||
}
|
||||
|
||||
var relevant_kitty_opts = sync.OnceValue(func() KittyOpts {
|
||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
||||
return read_relevant_kitty_opts()
|
||||
})
|
||||
|
||||
func get_shell_from_kitty_conf() (shell string) {
|
||||
|
||||
Reference in New Issue
Block a user