From e9e1e9f36359abd824496d6cc68025218580fea1 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Jan 2018 20:43:07 +0100 Subject: [PATCH] Add Kubernetes Context (#257) --- README.md | 11 +++++++++++ bullet-train.zsh-theme | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 79476c9..61cf3ae 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,17 @@ NOTE: You do not need to specify *end* segment - it will be added automatically. |`BULLETTRAIN_GO_FG`|`white`|Foreground color |`BULLETTRAIN_GO_PREFIX`|`go`|Prefix of the segment +### Kubernetes Context + +|Variable|Default|Meaning +|--------|-------|-------| +|`BULLETTRAIN_KCTX_BG`|`yellow`|Background color +|`BULLETTRAIN_KCTX_FG`|`white`|Foreground color +|`BULLETTRAIN_KCTX_PREFIX`|`⎈`|[Kubernetes](https://unicode-table.com/de/2388/) prefix of the segment +|`BULLETTRAIN_KCTX_KCONFIG`|``|Location of kube config file (e.g. /Users/Hugo/.kube/config) + +`BULLETTRAIN_KCTX_KCONFIG` must be set, e.g. in .zshrc. There can be no default value and `~/` can not be reliably interpreted. The prompt will also do a sanity check whether `kubectl` is installed. If either condition fails, the prompt segment will not be drawn at all. + ### AWS Profile Displays which AWS (Amazon Web Services) credentials profile is currently set. diff --git a/bullet-train.zsh-theme b/bullet-train.zsh-theme index b495bd9..453d673 100644 --- a/bullet-train.zsh-theme +++ b/bullet-train.zsh-theme @@ -139,6 +139,17 @@ if [ ! -n "${BULLETTRAIN_GO_PREFIX+1}" ]; then BULLETTRAIN_GO_PREFIX="go" fi +# Kubernetes Context +if [ ! -n "${BULLETTRAIN_KCTX_BG+1}" ]; then + BULLETTRAIN_KCTX_BG=yellow +fi +if [ ! -n "${BULLETTRAIN_KCTX_FG+1}" ]; then + BULLETTRAIN_KCTX_FG=white +fi +if [ ! -n "${BULLETTRAIN_KCTX_PREFIX+1}" ]; then + BULLETTRAIN_KCTX_PREFIX="⎈" +fi + # ELIXIR if [ ! -n "${BULLETTRAIN_ELIXIR_BG+1}" ]; then BULLETTRAIN_ELIXIR_BG=magenta @@ -518,6 +529,18 @@ prompt_go() { fi } +# Kubernetes Context +prompt_kctx() { + if [[ ! -n $BULLETTRAIN_KCTX_KCONFIG ]]; then + return + fi + if command -v kubectl > /dev/null 2>&1; then + if [[ -f $BULLETTRAIN_KCTX_KCONFIG ]]; then + prompt_segment $BULLETTRAIN_KCTX_BG $BULLETTRAIN_KCTX_FG $BULLETTRAIN_KCTX_PREFIX" $(cat $BULLETTRAIN_KCTX_KCONFIG|grep current-context| awk '{print $2}')" + fi + fi +} + # Virtualenv: current working virtualenv prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV"