Added the k8s namespace value to the prompt and the k8s icon to the segment (#208)

This commit is contained in:
Sergei Morozov 2019-07-01 12:21:31 -07:00 committed by Justin Hileman
parent 1abb331c60
commit 5389a26442
2 changed files with 29 additions and 7 deletions

View File

@ -579,10 +579,7 @@ function __bobthefish_prompt_docker -S -d 'Display Docker machine name'
echo -ns $DOCKER_MACHINE_NAME ' ' echo -ns $DOCKER_MACHINE_NAME ' '
end end
function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context' function __bobthefish_k8s_context -S -d 'Get the current k8s context'
[ "$theme_display_k8s_context" = 'yes' ]
or return
set -l config_paths "$HOME/.kube/config" set -l config_paths "$HOME/.kube/config"
[ -n "$KUBECONFIG" ] [ -n "$KUBECONFIG" ]
and set config_paths (string split ':' "$KUBECONFIG") $config_paths 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:' ] if [ "$key" = 'current-context:' ]
set -l context (string trim -c '"\' ' -- $val) set -l context (string trim -c '"\' ' -- $val)
[ -z "$context" ] [ -z "$context" ]
and return and return 1
__bobthefish_start_segment $color_k8s echo $context
echo -ns $context ' '
return return
end end
end <$file end <$file
end 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 end

View File

@ -25,6 +25,9 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
# Desk glyphs # Desk glyphs
set -x desk_glyph \u25F2 set -x desk_glyph \u25F2
# Kubernetes glyphs
set -x k8s_glyph \u2388 # '⎈'
# Vagrant glyphs # Vagrant glyphs
set -x vagrant_running_glyph \u2191 # ↑ 'running' set -x vagrant_running_glyph \u2191 # ↑ 'running'
set -x vagrant_poweroff_glyph \u2193 # ↓ 'poweroff' set -x vagrant_poweroff_glyph \u2193 # ↓ 'poweroff'