diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 9bb144d..41d31c4 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -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 diff --git a/zsh/ohmyzsh/themes/laptop-hostname.zsh-theme b/zsh/ohmyzsh/themes/laptop-hostname.zsh-theme index e78e058..1a4e795 100644 --- a/zsh/ohmyzsh/themes/laptop-hostname.zsh-theme +++ b/zsh/ohmyzsh/themes/laptop-hostname.zsh-theme @@ -77,7 +77,7 @@ else fi local return_code="" -local git_branch='$(git_prompt_info)' +local git_branch=' $(git_prompt_info)' 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}' +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 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%})" fi RPS1=" ${return_code}"