Show kubeconfig in prompt

This commit is contained in:
Thomas Forgione 2023-02-17 09:50:47 +01:00
parent a9c33ba704
commit bcc4ffa91a
2 changed files with 30 additions and 3 deletions

View File

@ -94,6 +94,25 @@ if [ $? -eq 0 ]; then
alias dcd="docker-compose down" alias dcd="docker-compose down"
fi fi
command -v kubectl > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Sets the kube config
kube() {
local kube_config=$HOME/.kubes/$1/config
if [ $# -ne 1 ]; then
echo >&2 error: kube expects a single argument
return 1
elif [ ! -f $kube_config ]; then
echo >&2 error: no such kube config: $kube_config
return 1
else
export KUBECONFIG=$kube_config
fi
}
fi
# change to git directory # change to git directory
cdg() { cdg() {
local newdir local newdir

View File

@ -77,7 +77,7 @@ else
fi fi
local return_code="" local return_code=""
local git_branch='$(git_prompt_info)' local git_branch=' $(git_prompt_info)'
local PR_TEMP="" local PR_TEMP=""
@ -85,16 +85,24 @@ command -v vcgencmd > /dev/null && PR_TEMP=' ${PR_GREEN}$(vcgencmd measure_te
local PR_DATE='${PR_BOLD}${PR_MAGENTA}[%D{%H:%M}]${PR_NO_COLOR}' local PR_DATE='${PR_BOLD}${PR_MAGENTA}[%D{%H:%M}]${PR_NO_COLOR}'
extract_kube() {
if [ ! -z $KUBECONFIG ]; then
echo " ${PR_CYAN}$(echo $KUBECONFIG | rev | cut -d '/' -f 2 | rev)${PR_NO_COLOR}"
fi
}
local kube='$(extract_kube)'
#PROMPT="${user_host} ${current_dir} ${rvm_ruby}${git_branch}$PR_PROMPT " #PROMPT="${user_host} ${current_dir} ${rvm_ruby}${git_branch}$PR_PROMPT "
separator='${PR_YELLOW}::${PR_NO_COLOR}' separator='${PR_YELLOW}::${PR_NO_COLOR}'
tty | read tty_value tty | read tty_value
if [[ $tty_value == *pts* ]]; then # if in a tty if [[ $tty_value == *pts* ]]; then # if in a tty
PROMPT="$PR_ARROW_UP${PR_DATE} ${user_host}${separator}${PR_NO_COLOR}${current_dir} ${rvm_ruby}${git_branch}${PR_TEMP} PROMPT="$PR_ARROW_UP${PR_DATE} ${user_host}${separator}${PR_NO_COLOR}${current_dir}${rvm_ruby}${git_branch}${kube}${PR_TEMP}
$PR_ARROW_DOWN$PR_PROMPT ${PR_NO_COLOR}" $PR_ARROW_DOWN$PR_PROMPT ${PR_NO_COLOR}"
return_code="%(?.%{$PR_GREEN%}%? ↵%{$PR_NO_COLOR%}.%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})" return_code="%(?.%{$PR_GREEN%}%? ↵%{$PR_NO_COLOR%}.%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})"
else else
eval PR_NO_COLOR="$PR_WHITE" eval PR_NO_COLOR="$PR_WHITE"
PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}> ${PR_NO_COLOR}" PROMPT="${user_host} ${current_dir} ${rvm_ruby}${git_branch}> ${PR_NO_COLOR}"
return_code="%(?.%{$PR_GREEN%}%? <%{$PR_NO_COLOR%}.%{$PR_RED%}%? <%{$PR_NO_COLOR%})" return_code="%(?.%{$PR_GREEN%}%? <%{$PR_NO_COLOR%}.%{$PR_RED%}%? <%{$PR_NO_COLOR%})"
fi fi
RPS1=" ${return_code}" RPS1=" ${return_code}"