Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Add custom color for context/namespace support #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ kube_ps on
kube_ps off
```

You can set custom color for a context/namespace by adding env vars like this:

```fish
set -Ux KUBE_PROMPT_COLOR_CTX red
set -Ux KUBE_PROMPT_COLOR_NS blue
```

`kube_ps` is a simple function that just updates a universal variable
`__kube_ps_enabled`.

Expand Down
8 changes: 6 additions & 2 deletions __kube_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# https://github.com/jonmosco/kube-ps1
# https://github.com/Ladicle/fish-kubectl-prompt

set -g color_ctx (set_color $KUBE_PROMPT_COLOR_CTX)
set -g color_ns (set_color $KUBE_PROMPT_COLOR_NS)

function __kube_ps_update_cache
function __kube_ps_cache_context
set -l ctx (kubectl config current-context 2>/dev/null)
if /bin/test $status -eq 0
set -g __kube_ps_context "$ctx"
set -g __kube_ps_context "$color_ctx$ctx"
else
set -g __kube_ps_context "n/a"
end
Expand All @@ -15,7 +18,7 @@ function __kube_ps_update_cache
function __kube_ps_cache_namespace
set -l ns (kubectl config view --minify -o 'jsonpath={..namespace}' 2>/dev/null)
if /bin/test -n "$ns"
set -g __kube_ps_namespace "$ns"
set -g __kube_ps_namespace "$color_ns$ns"
else
set -g __kube_ps_namespace "default"
end
Expand Down Expand Up @@ -55,3 +58,4 @@ function __kube_prompt
__kube_ps_update_cache
echo -n -s " (⎈ $__kube_ps_context|$__kube_ps_namespace)"
end