From d8d6c752fdeabf4de96ba96a361069e1fe8e65da Mon Sep 17 00:00:00 2001 From: Jordan Taylor Date: Fri, 26 May 2017 09:02:14 -0400 Subject: [PATCH 1/7] added the current context prompt for your kubectl config --- powerlevel9k.zsh-theme | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 666ce965..fa2e94ab 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1353,6 +1353,20 @@ prompt_dir_writable() { fi } +# Kubernetes Current Context +prompt_kubecontext() { + local kubectl=$(kubectl version 2>/dev/null) + + if [[ -n "kubectl_version" ]]; then + # Get the current Kubernetes config context's namespaece + local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}') + # Get the current Kuberenetes context + local k8s_context=$(kubectl config current-context) + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace \u2388" + fi +} + + ################################################################ # Prompt processing and drawing ################################################################ From c11c3a55de2be5a9e11b55426d0afbca43aace4d Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:27:17 -0500 Subject: [PATCH 2/7] use p9k print_icon for kubecontext segment --- functions/icons.zsh | 4 ++++ powerlevel9k.zsh-theme | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 238b6b9e..e38d66a2 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -84,6 +84,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\UE89C' #  SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; 'awesome-fontconfig') @@ -152,6 +153,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE138' #  EXECUTION_TIME_ICON $'\uF253' SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -220,6 +222,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UF023' #  EXECUTION_TIME_ICON $'\uF252' #  SSH_ICON $'\uF489' #  + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; *) @@ -288,6 +291,7 @@ case $POWERLEVEL9K_MODE in LOCK_ICON $'\UE0A2' EXECUTION_TIME_ICON 'Dur' SSH_ICON '(ssh)' + KUBERNETES_ICON $'\U2388' # ⎈ ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index fa2e94ab..0d794a85 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1362,7 +1362,7 @@ prompt_kubecontext() { local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}') # Get the current Kuberenetes context local k8s_context=$(kubectl config current-context) - "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace \u2388" + "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON" fi } From 932e4edeaf5508a65e269e88668b588f2e6cac0f Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:29:06 -0500 Subject: [PATCH 3/7] fix variable name typo --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0d794a85..d86dfe27 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1355,9 +1355,9 @@ prompt_dir_writable() { # Kubernetes Current Context prompt_kubecontext() { - local kubectl=$(kubectl version 2>/dev/null) + local kubectl_version=$(kubectl version 2>/dev/null) - if [[ -n "kubectl_version" ]]; then + if [[ -n "$kubectl_version" ]]; then # Get the current Kubernetes config context's namespaece local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}') # Get the current Kuberenetes context From 6f0c809a7dd81a277b7c1ec5bf9b7272ef9e3d7f Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 13:34:11 -0500 Subject: [PATCH 4/7] empty namespace value is 'default' --- powerlevel9k.zsh-theme | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d86dfe27..668748d2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1362,6 +1362,10 @@ prompt_kubecontext() { local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}') # Get the current Kuberenetes context local k8s_context=$(kubectl config current-context) + + if [[ -z "$k8s_namespace" ]]; then + k8s_namespace="default" + fi "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON" fi } From d2ecb38d60e31494ae808a08d9f338df6367cafb Mon Sep 17 00:00:00 2001 From: Jason Hutchinson Date: Fri, 26 May 2017 14:02:18 -0500 Subject: [PATCH 5/7] add tests --- test/segments/kubecontext.spec | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 test/segments/kubecontext.spec diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec new file mode 100755 index 00000000..eaaa2300 --- /dev/null +++ b/test/segments/kubecontext.spec @@ -0,0 +1,80 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + # Load Powerlevel9k + source powerlevel9k.zsh-theme +} + +function mockKubectl() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'current-context') + echo 'minikube' + ;; + 'get-contexts') + echo '* minikube minikube minikube ' + ;; + esac + ;; + esac +} + +function mockKubectlOtherNamespace() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'current-context') + echo 'minikube' + ;; + 'get-contexts') + echo '* minikube minikube minikube kube-system' + ;; + esac + ;; + esac +} + +function testKubeContext() { + alias kubectl=mockKubectl + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + + assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unalias kubectl +} +function testKubeContextOtherNamespace() { + alias kubectl=mockKubectlOtherNamespace + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + + assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unalias kubectl +} +function testKubeContextPrintsNothingIfKubectlNotAvailable() { + alias kubectl=noKubectl + POWERLEVEL9K_CUSTOM_WORLD='echo world' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_CUSTOM_WORLD + unalias kubectl +} + +source shunit2/source/2.1/src/shunit2 From ef0b5ce50fdd4be764d189723e6b51088fadc286 Mon Sep 17 00:00:00 2001 From: Jordan Taylor Date: Sun, 28 May 2017 12:57:30 -0400 Subject: [PATCH 6/7] add kubecontext test spec file to travis build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 134f31f1..e0ad5a93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,3 +28,4 @@ script: - test/segments/rust_version.spec - test/segments/go_version.spec - test/segments/vcs.spec + - test/segments/kubecontext.spec From d6a14a9a010009866c60a2f4d52d0aefac93e876 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Fri, 2 Jun 2017 11:59:30 -0400 Subject: [PATCH 7/7] Updating README and CHANGELOG --- CHANGELOG.md | 22 ++++++++++++++++++++++ README.md | 1 + 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d6ecd18..0355c464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,25 @@ +## Next + +- Added `teardown` command to turn off P9k prompt. +- Fixes for P9k in Cygwin and 32-bit systems. +- Better colors in virtualization segments. +- Added 'Gopher' icon to the `go_version` segment. +- Improved detection in `nvm` +- Added option to support command status reading from piped command sequences. + +### New Segments: `host` and `user` + +Provides two separate segments for `host` and `user` in case you don't wont both +in one (per the `context` segment). + +### New Segment: `newline` + +Allows you to split segments across multiple lines. + +### New Segment: `kubecontext` + +Shows the current context of your `kubectl` configuration. + ## v0.6.4 - Significant enhancements to the `battery` segment. Check out the README to diff --git a/README.md b/README.md index 890875ad..678cf0b9 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ The segments that are currently available are: * [`aws`](#aws) - The current AWS profile, if active. * `aws_eb_env` - The current Elastic Beanstalk Environment. * `docker_machine` - The current Docker Machine. +* `kubecontext` - The current context of your `kubectl` configuration. **Other:** * [`custom_command`](#custom_command) - Create a custom segment to display the