From 711a8b8fdf12ee611c8b514c25fb783df2f54372 Mon Sep 17 00:00:00 2001 From: Alex Trinker Date: Tue, 15 Jul 2025 06:57:12 +0200 Subject: [PATCH] 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 --- README.md | 4 ++-- internal/ui/config.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ee642ee..5ca29107 100644 --- a/README.md +++ b/README.md @@ -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. reactive: false # 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 defaultsToFullScreen: 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 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 -`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. This is a collection of {context_name, skin} tuples (please see example below!) diff --git a/internal/ui/config.go b/internal/ui/config.go index cca88fa3..0845e5a9 100644 --- a/internal/ui/config.go +++ b/internal/ui/config.go @@ -195,6 +195,14 @@ func (c *Configurator) activeSkin() (string, bool) { 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 _, err := os.Stat(config.SkinFileFromName(ct.Skin)); err == nil { skin = ct.Skin @@ -202,13 +210,15 @@ func (c *Configurator) activeSkin() (string, bool) { slogs.Skin, skin, 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 { skin = sk slog.Debug("Loading global skin", slogs.Skin, skin) + return skin, true } }