From 876e55fc4442f6e2e5b78f66d578e4f144339370 Mon Sep 17 00:00:00 2001 From: hophacker Date: Fri, 19 Feb 2021 17:09:41 +0800 Subject: [PATCH] and k8s command: cmd and kcp --- zsh/k8s.zsh | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/zsh/k8s.zsh b/zsh/k8s.zsh index 5220283..956ba39 100644 --- a/zsh/k8s.zsh +++ b/zsh/k8s.zsh @@ -2,6 +2,9 @@ NAMESPACE=default RUNNING_POD="" LEFT_ARGS="" KCONTEXT="" +VERBOSE=false +SRC="" +DST="" # aliases alias k="kubectl" @@ -16,21 +19,27 @@ function getpod { echo "Usage : $0 [options] [--] Options: -K kubectl context - -R not randomly select pod + -R Not randomly select pod + -d Destination + -s Source -n NAMESPACE -p PROJECT + -v Verbose -h Display this message" } - while getopts ":hvK:Rp:" opt + while getopts ":hvs:d:K:Rp:" opt do case $opt in - R) RAN=false ;; - h) usage; return 0 ;; - n) NAMESPACE=$OPTARG ;; - p) PROJECT=$OPTARG ;; - K) KCONTEXT=$OPTARG ;; + R) RAN=false ;; + s) SRC=$OPTARG ;; + d) DST=$OPTARG ;; + n) NAMESPACE=$OPTARG ;; + p) PROJECT=$OPTARG ;; + K) KCONTEXT=$OPTARG ;; + v) VERBOSE=true ;; + h) usage; return 0 ;; *) echo -e "\n Option does not exist: $OPTARG\n" - usage; return 1 ;; + usage; return 1 ;; esac done shift $(($OPTIND-1)) @@ -93,6 +102,19 @@ function kexec { fi } +function cmd { + if $VERBOSE; then + echo "Running: $fg[green]$1$reset_color" + fi + eval $1 +} +function kcp { + getpod $@ + if [[ $RUNNING_POD != "" ]]; then + cmd "kubectl -n $NAMESPACE cp $RUNNING_POD:$SRC $DST" + fi +} + function klogs { finalopts=() while [[ $@ != "" ]] do