Created
June 21, 2017 06:11
-
-
Save StephanX/1f64658c736be6f9144b5b936e63fb4c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# configures bash prompt based on current kubernetes cluster context and namespace | |
# based on https://pracucci.com/display-the-current-kubelet-context-in-the-bash-prompt.html | |
__kube_ps1() | |
{ | |
CONTEXT=$(kubectl config view | grep current-context | awk '{ print $NF }' | awk -F '.' '{ print $1 }') | |
NS=$(kubectl config view $(kubectl config current-context) | grep namespace | awk '{ print $2 }') | |
if [ -n "$CONTEXT" ]; then | |
echo "[${CONTEXT}][${NS}]" | |
fi | |
} | |
NORMAL="\[\e[00m\]" # Normal | |
BLACK="\[\e[0;30m\]" # Black | |
RED="\[\e[1;31m\]" # Red | |
GREEN="\[\e[0;32m\]" # Green | |
YELLOW="\[\e[0;33m\]" # Yellow | |
BLUE="\[\e[0;34m\]" # Blue | |
PURPLE="\[\e[0;35m\]" # Purple | |
CYAN="\[\e[0;36m\]" # Cyan | |
WHITE="\[\e[0;37m\]" # White | |
export PS1="${BLUE}\h:${PURPLE}\$(__kube_ps1) ${BLUE}\W> ${NORMAL}" | |
# results: | |
# Cronos:[dev1][qa1] mydirectory> | |
# || || | |
# Hostname:[cluster][namespace] currentdir> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps