diff --git a/fish_prompt.fish b/fish_prompt.fish index 0cb72d26..ec8e23ae 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -579,10 +579,7 @@ function __bobthefish_prompt_docker -S -d 'Display Docker machine name' echo -ns $DOCKER_MACHINE_NAME ' ' end -function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context' - [ "$theme_display_k8s_context" = 'yes' ] - or return - +function __bobthefish_k8s_context -S -d 'Get the current k8s context' set -l config_paths "$HOME/.kube/config" [ -n "$KUBECONFIG" ] and set config_paths (string split ':' "$KUBECONFIG") $config_paths @@ -595,14 +592,36 @@ function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context' if [ "$key" = 'current-context:' ] set -l context (string trim -c '"\' ' -- $val) [ -z "$context" ] - and return + and return 1 - __bobthefish_start_segment $color_k8s - echo -ns $context ' ' + echo $context return end end <$file end + + return 1 +end + +function __bobthefish_k8s_namespace -S -d 'Get the current k8s namespace' + kubectl config view --minify --output "jsonpath={..namespace}" +end + +function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context' + [ "$theme_display_k8s_context" = 'yes' ] + or return + + set -l context (__bobthefish_k8s_context) + or return + + set -l namespace (__bobthefish_k8s_namespace) + + set -l segment $k8s_glyph " " $context + [ -n "$namespace" ] + and set segment $segment ":" $namespace + + __bobthefish_start_segment $color_k8s + echo -ns $segment " " end diff --git a/functions/__bobthefish_glyphs.fish b/functions/__bobthefish_glyphs.fish index 10c01267..6d82b664 100644 --- a/functions/__bobthefish_glyphs.fish +++ b/functions/__bobthefish_glyphs.fish @@ -25,6 +25,9 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish' # Desk glyphs set -x desk_glyph \u25F2 + # Kubernetes glyphs + set -x k8s_glyph \u2388 # '⎈' + # Vagrant glyphs set -x vagrant_running_glyph \u2191 # ↑ 'running' set -x vagrant_poweroff_glyph \u2193 # ↓ 'poweroff'