From 6b3d0b0167978ccf5ebe9a64cdbcb5b7434435b9 Mon Sep 17 00:00:00 2001 From: hophacker Date: Sun, 17 Jan 2021 16:01:09 +0800 Subject: [PATCH] move k8s related functions into k8s.zsh --- zsh/aliases.zsh | 6 ------ zsh/k8s.zsh | 16 ++++++++++++++++ zsh/prezto-themes/prompt_skwp_setup | 8 +------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 45960b3..f049c90 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -216,12 +216,6 @@ alias brewu='brew update && brew upgrade && brew cleanup && brew doctor' # emacs alias emacs="env LC_CTYPE=zh_CN.UTF-8 emacs" -# k8s -alias k="kubectl" -alias kpg="kubectl get pods | grep" -alias ksg="kubectl get service | grep" -alias k_get_pods_sort_by_time="k get pods --sort-by=.metadata.creationTimestamp" - # rails alias rails_setup='rails db:reset; rails db:seed RAILS_ENV=test' alias rails_test='rspec && rubocop' diff --git a/zsh/k8s.zsh b/zsh/k8s.zsh index aa43cb9..5220283 100644 --- a/zsh/k8s.zsh +++ b/zsh/k8s.zsh @@ -2,6 +2,13 @@ NAMESPACE=default RUNNING_POD="" LEFT_ARGS="" KCONTEXT="" + +# aliases +alias k="kubectl" +alias kpg="kubectl get pods | grep" +alias ksg="kubectl get service | grep" +alias k_get_pods_sort_by_time="k get pods --sort-by=.metadata.creationTimestamp" + function getpod { RAN=true function usage () @@ -157,3 +164,12 @@ function k_force_delete_pod () { function k_get_containers_of_pod { k get pods $1 -o jsonpath='{.spec.containers[*].name}*' } +function set_k8s_context_core { + 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 +} diff --git a/zsh/prezto-themes/prompt_skwp_setup b/zsh/prezto-themes/prompt_skwp_setup index 119b32b..3bbafde 100644 --- a/zsh/prezto-themes/prompt_skwp_setup +++ b/zsh/prezto-themes/prompt_skwp_setup @@ -69,13 +69,7 @@ function prompt_skwp_setup { 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 + set_k8s_context_core $* prompt_skwp_setup } prompt_skwp_setup