From 611d712af4e89fac7291f68a8951470d2893ddda Mon Sep 17 00:00:00 2001 From: hophacker Date: Thu, 5 Mar 2020 16:25:29 +0800 Subject: [PATCH] add func set_k8s_context and force you to select context, then deal with k8s with that context --- zsh/aliases.zsh | 1 - zsh/functions.zsh | 5 ----- zsh/prezto-themes/prompt_skwp_setup | 12 +++++++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index c0f529b..e5965ad 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -254,5 +254,4 @@ alias find_large_files="sudo find / -xdev -type f -size +50M" alias vim_plain="vim -u NONE" alias edit_alias="vim $yadr_zsh/aliases.zsh $yadr_zsh/functions.zsh -p" alias docker_purge='docker stop $(docker ps -qa);docker rm $(docker ps -qa)' -alias pzsh='USING_PROXYCHAINS=true proxychains zsh' alias yarn_sass="SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ yarn" diff --git a/zsh/functions.zsh b/zsh/functions.zsh index d7e8d96..f4a6970 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -237,7 +237,6 @@ function gitcopy() { fi } function kubectl() { - KCONTEXT=${KCONTEXT:-gcloud} DEBUG=false finalopts=() while [[ $@ != "" ]] do @@ -268,7 +267,6 @@ function kubectl() { command kubectl --kubeconfig=$HOME/.kube/${KCONTEXT}_config $finalopts } function stern { - KCONTEXT=${KCONTEXT:-gcloud} finalopts=() while [[ $@ != "" ]] do case $1 in @@ -290,7 +288,6 @@ function stern { command stern $finalopts -t --since 10m --kubeconfig=$HOME/.kube/${KCONTEXT}_config } function helm() { - KCONTEXT=${KCONTEXT:-gcloud} DEBUG=false finalopts=() while [[ $@ != "" ]] do @@ -324,7 +321,6 @@ function helm() { } function kexec { RAN=false - KCONTEXT=${KCONTEXT:-gcloud} NAMESPACE=default finalopts=() while [[ $@ != "" ]] do @@ -408,7 +404,6 @@ function kexec { } function klogs { - KCONTEXT=${KCONTEXT:-gcloud} finalopts=() while [[ $@ != "" ]] do case $1 in diff --git a/zsh/prezto-themes/prompt_skwp_setup b/zsh/prezto-themes/prompt_skwp_setup index 1635915..cf6e72e 100644 --- a/zsh/prezto-themes/prompt_skwp_setup +++ b/zsh/prezto-themes/prompt_skwp_setup @@ -70,10 +70,20 @@ function prompt_skwp_setup { zstyle ':prezto:module:ruby:info:version' format '[%v]' PROMPT="${__PROMPT_SKWP_COLORS[3]}%n%f ${__PROMPT_SKWP_COLORS[5]}%~%f "'$git_info[prompt]'"$ " - [[ $USING_PROXYCHAINS == 'true' ]] && PROMPT="🔗 $PROMPT" + [[ "$KCONTEXT" != "" ]] && PROMPT="%F{blue}$KCONTEXT💡 $PROMPT" RPROMPT='%F{blue}${ruby_info[version]}' } alias disable_git_info='DISABLE_GIT_INFO=1' alias enable_git_info='DISABLE_GIT_INFO=0' +function set_k8s_context { + C=$1 + if [[ "$C" == "" ]]; then + echo "Select your context:" + ls ~/.kube/*_config | xargs -n 1 basename | sed s/_config//g + read C + fi + export KCONTEXT=$C + prompt_skwp_setup +} prompt_skwp_setup "$@"