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"
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
cdg() {
local newdir

View File

@ -85,11 +85,19 @@ 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}'
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 "
separator='${PR_YELLOW}::${PR_NO_COLOR}'
tty | read tty_value
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}"
return_code="%(?.%{$PR_GREEN%}%? ↵%{$PR_NO_COLOR%}.%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})"
else