Created
February 21, 2026 10:29
-
-
Save ismailyenigul/f8523c1237dd9cff17567935804e4c84 to your computer and use it in GitHub Desktop.
Colorized k8s Context Manager for Bobthefish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Name: k8s_manager.fish | |
| # Description: Colorized Context Manager for the 'bobthefish' theme. | |
| # Features: fzf switcher, environment-aware coloring, and a toggle. | |
| # Installation: Place in ~/.config/fish/conf.d/k8s_manager.fish | |
| # see https://ismailyenigul.medium.com/toggling-kubernetes-context-in-fish-shell-2fb3b67040aa for details | |
| # 1. THEME PREFERENCES | |
| # ----------------------------------------------------------------------------- | |
| set -g theme_display_k8s_context yes | |
| set -g theme_display_date no | |
| set -g theme_color_scheme dark | |
| # 2. STATE MANAGEMENT (Toggle) | |
| # ----------------------------------------------------------------------------- | |
| # Initialize the toggle as a Universal variable to persist across sessions. | |
| if not set -q K8S_PROMPT_ENABLED | |
| set -U K8S_PROMPT_ENABLED "true" | |
| end | |
| function k8sctx --description "Toggle the Colorized k8s Context Manager on/off" | |
| if test "$K8S_PROMPT_ENABLED" = "true" | |
| set -U K8S_PROMPT_ENABLED "false" | |
| set -g theme_display_k8s_context no | |
| echo (set_color red)"K8s Smart Colors: OFF (Theme Default)"(set_color normal) | |
| else | |
| set -U K8S_PROMPT_ENABLED "true" | |
| set -g theme_display_k8s_context yes | |
| echo (set_color green)"K8s Smart Colors: ON"(set_color normal) | |
| end | |
| # Force a prompt refresh to show changes immediately | |
| commandline -f repaint | |
| end | |
| # 3. CONTEXT SWITCHER (fzf) | |
| # ----------------------------------------------------------------------------- | |
| function k8sct --description "Search and switch Kubernetes contexts using fzf" | |
| if not type -q fzf | |
| echo (set_color red)"Error: fzf is not installed."(set_color normal); return 1 | |
| end | |
| # Extract context names and pipe into fzf for selection | |
| set -l ctx (kubectl config get-contexts -o name | fzf --height 40% --reverse --border --prompt="Select K8s Context: ") | |
| if test -n "$ctx" | |
| kubectl config use-context $ctx | |
| commandline -f repaint | |
| end | |
| end | |
| # 4. THEME COLOR OVERRIDE (The "Brain") | |
| # ----------------------------------------------------------------------------- | |
| # We redefine 'bobthefish_colors' to inject our logic into the theme engine. | |
| function bobthefish_colors | |
| # Set the standard 'dark' theme palette manually | |
| set -gx color_initial_segment_exit red --bold | |
| set -gx color_initial_segment_su green --bold | |
| set -gx color_initial_segment_jobs blue --bold | |
| set -gx color_path 444444 bcbcbc | |
| set -gx color_path_basename 444444 ffffff --bold | |
| set -gx color_repo 333333 green | |
| set -gx color_repo_dirty 333333 red | |
| set -gx color_repo_staged 333333 yellow | |
| set -gx color_vi_mode_default 333333 909090 --bold | |
| set -gx color_vi_mode_insert 333333 af5f00 --bold | |
| set -gx color_vi_mode_visual 333333 5f8700 --bold | |
| set -gx color_aws_vault 333333 5f9ea0 | |
| set -gx color_username 222222 ffffff --bold | |
| set -gx color_hostname 222222 ffffff | |
| # Apply custom environmental colors only if the toggle is enabled | |
| if test "$K8S_PROMPT_ENABLED" = "true" | |
| set -l ctx (kubectl config current-context 2>/dev/null) | |
| # Environmental Color Mapping | |
| if string match -q "*-prod*" $ctx | |
| # PRODUCTION: Red Background | |
| set -gx color_k8s red white --bold | |
| else if string match -q "*-preprod*" $ctx | |
| # PREPROD: Yellow Background | |
| set -gx color_k8s yellow black --bold | |
| else if string match -q "*-stage*" $ctx | |
| # STAGING: Cyan Background | |
| set -gx color_k8s cyan black --bold | |
| else if string match -q "*dev*" $ctx; or string match -q "*-nonprod*" $ctx | |
| # DEV/NONPROD: Green Background | |
| set -gx color_k8s green black --bold | |
| else | |
| # DEFAULT/UNKNOWN: White Background | |
| set -gx color_k8s white black | |
| end | |
| else | |
| # Standard Theme Default (Green) | |
| set -gx color_k8s green black | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment