allow skin to be selected via K9S_SKIN env var (#3356)

* allow skin to be set via env var K9S_SKIN

* use `return` after skin selection

* add K9S_SKIN to README
mine
Alex Trinker 2025-07-15 06:57:12 +02:00 committed by GitHub
parent 11d40cab57
commit 711a8b8fdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -438,7 +438,7 @@ You can now override the context portForward default address configuration by se
# Toggles reactive UI. This option provide for watching on disk artifacts changes and update the UI live Defaults to false. # Toggles reactive UI. This option provide for watching on disk artifacts changes and update the UI live Defaults to false.
reactive: false reactive: false
# By default all contexts will use the dracula skin unless explicitly overridden in the context config file. # By default all contexts will use the dracula skin unless explicitly overridden in the context config file.
skin: dracula # => assumes the file skins/dracula.yaml is present in the $XDG_DATA_HOME/k9s/skins directory skin: dracula # => assumes the file skins/dracula.yaml is present in the $XDG_DATA_HOME/k9s/skins directory. Can be overriden with K9S_SKIN.
# Allows to set certain views default fullscreen mode. (yaml, helm history, describe, value_extender, details, logs) Default false # Allows to set certain views default fullscreen mode. (yaml, helm history, describe, value_extender, details, logs) Default false
defaultsToFullScreen: false defaultsToFullScreen: false
# Show full resource GVR (Group/Version/Resource) vs just R. Default: false. # Show full resource GVR (Group/Version/Resource) vs just R. Default: false.
@ -1039,7 +1039,7 @@ Example: Dracula Skin ;)
You can style K9s based on your own sense of look and style. Skins are YAML files, that enable a user to change the K9s presentation layer. See this repo `skins` directory for examples. You can style K9s based on your own sense of look and style. Skins are YAML files, that enable a user to change the K9s presentation layer. See this repo `skins` directory for examples.
You can skin k9s by default by specifying a UI.skin attribute. You can also change K9s skins based on the context you are connecting too. You can skin k9s by default by specifying a UI.skin attribute. You can also change K9s skins based on the context you are connecting too.
In this case, you can specify a skin field on your cluster config aka `skin: dracula` (just the name of the skin file without the extension!) and copy this repo In this case, you can specify a skin field on your cluster config aka `skin: dracula` (just the name of the skin file without the extension!) and copy this repo
`skins/dracula.yaml` to `$XDG_CONFIG_HOME/k9s/skins/` directory. `skins/dracula.yaml` to `$XDG_CONFIG_HOME/k9s/skins/` directory. You can also change the skin by setting `K9S_SKIN` in the environment, e.g. `export K9S_SKIN="dracula"`.
In the case where your cluster spans several contexts, you can add a skin context configuration to your context configuration. In the case where your cluster spans several contexts, you can add a skin context configuration to your context configuration.
This is a collection of {context_name, skin} tuples (please see example below!) This is a collection of {context_name, skin} tuples (please see example below!)

View File

@ -195,6 +195,14 @@ func (c *Configurator) activeSkin() (string, bool) {
return skin, false return skin, false
} }
if env_skin := os.Getenv("K9S_SKIN"); env_skin != "" {
if _, err := os.Stat(config.SkinFileFromName(env_skin)); err == nil {
skin = env_skin
slog.Debug("Loading env skin", slogs.Skin, skin)
return skin, true
}
}
if ct, err := c.Config.K9s.ActiveContext(); err == nil && ct.Skin != "" { if ct, err := c.Config.K9s.ActiveContext(); err == nil && ct.Skin != "" {
if _, err := os.Stat(config.SkinFileFromName(ct.Skin)); err == nil { if _, err := os.Stat(config.SkinFileFromName(ct.Skin)); err == nil {
skin = ct.Skin skin = ct.Skin
@ -202,13 +210,15 @@ func (c *Configurator) activeSkin() (string, bool) {
slogs.Skin, skin, slogs.Skin, skin,
slogs.Context, c.Config.K9s.ActiveContextName(), slogs.Context, c.Config.K9s.ActiveContextName(),
) )
return skin, true
} }
} }
if sk := c.Config.K9s.UI.Skin; skin == "" && sk != "" { if sk := c.Config.K9s.UI.Skin; sk != "" {
if _, err := os.Stat(config.SkinFileFromName(sk)); err == nil { if _, err := os.Stat(config.SkinFileFromName(sk)); err == nil {
skin = sk skin = sk
slog.Debug("Loading global skin", slogs.Skin, skin) slog.Debug("Loading global skin", slogs.Skin, skin)
return skin, true
} }
} }