Created
July 23, 2019 12:41
-
-
Save mcfedr/30fdbe3a6f9cd3f61994adc5d1e364da to your computer and use it in GitHub Desktop.
Bash prompt including current AWS profile, gcloud context, k8s context+namespace
This file contains hidden or 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
# prompt | |
__aws_ps1() { | |
local printf_format="$1" | |
local profile="${AWS_PROFILE:-ekreative}" | |
if [ "$profile" != "ekreative" ]; then | |
printf -- "$printf_format" "${AWS_PROFILE:-ekreative}" | |
fi | |
} | |
__gcloud_ps1() { | |
local printf_format="$1" | |
local context=$(cat $HOME/.config/gcloud/active_config) | |
if [ "$context" != "" ] && [ "$context" != "ekreative" ]; then | |
printf -- "$printf_format" "$context" | |
fi | |
} | |
__k8s_ps1() { | |
local printf_format="$1" | |
local context=$(kubectl config current-context) | |
if [ "$context" != "" ]; then | |
local namespace="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${context}\")].context.namespace}")" | |
if [ "$namespace" != "" ] && [ "$namespace" != "default" ]; then | |
context="${context}:${namespace}" | |
fi | |
printf -- "$printf_format" "$context" | |
fi | |
} | |
__status_ps1() { | |
local printf_format="$1" | |
if [ "$?" -eq 0 ]; then | |
printf -- "$printf_format" "0" | |
else | |
printf -- "$printf_format" "1" | |
fi | |
} | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWSTASHSTATE=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
# There is a work around for iterm bug, using zero width markers (\[ and \]) for the second part of cloud \xe2\x98\x81\[\xef\xb8\x8f\] | |
# https://gitlab.com/gnachman/iterm2/issues/6130 | |
PS1='${LOGNAME/mcfedr/}\h $(__aws_ps1 "\[\e[1;31m\][\xf0\x9f\x93\x95 %s]\[\e[m\]")$(__gcloud_ps1 "\[\e[1;34m\][\xf0\x9f\xa7\xa9 %s]\[\e[m\]")$(__k8s_ps1 "\[\e[1;36m\][\xf0\x9f\x9a\xa2 %s]\[\e[m\]") \[\e[1;33m\]\w\[\e[m\] $(__git_ps1 "\[\e[1;32m\][%s] \[\e[m\]")$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment