Last active
February 14, 2023 23:46
-
-
Save nicolaballotta/cab3e389e5fb541222677e5b4ec90c7f to your computer and use it in GitHub Desktop.
Add Kubernetes context to your zsh prompt (for Agnoster theme, but can easily be adapted to different themes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# INSTALLATION | |
# - Add the following function to your .oh-my-zsh/themes/agnoster.zsh-theme | |
# - Call prompt_kubecontext from build_prompt() as showed in the example below | |
# | |
# | |
# build_prompt() { | |
# prompt_kubecontext | |
# } | |
prompt_kubecontext() { | |
if [[ $(kubectl config current-context) == *"testing"* ]]; then | |
prompt_segment green black "(`kubectl config current-context`)" | |
elif [[ $(kubectl config current-context) == *"staging"* ]]; then | |
prompt_segment yellow black "(`kubectl config current-context`)" | |
elif [[ $(kubectl config current-context) == *"production"* ]]; then | |
prompt_segment red yellow "(`kubectl config current-context`)" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but if you have to modify the prompt kube-ps1 is not useful, you can use below :