found a way to wrap extra arguments around an existing command, and apply it to kubectl and stern

This commit is contained in:
hophacker 2020-01-30 22:08:18 +08:00
parent 9473088c32
commit 4c0d689645

View File

@ -236,19 +236,51 @@ function gitcopy() {
ruby ~/Projects/paiyou-hub/bin/trello_action.rb -n $trelloCardName -d "$commits" -u `git config user.name` ruby ~/Projects/paiyou-hub/bin/trello_action.rb -n $trelloCardName -d "$commits" -u `git config user.name`
fi fi
} }
function k() { function kubectl() {
CONTEXT=gcloud CONTEXT=gcloud
while getopts ":c:" opt; do finalopts=()
case ${opt} in while [[ $@ != "" ]] do
c) case $1 in
CONTEXT=$OPTARG -c)
CONTEXT="$2"
shift
shift
;; ;;
\?) echo "Usage: h [-c CONTEXT]" --context=*)
CONTEXT="${i#*=}"
shift
;;
*)
finalopts+=($1)
shift
;; ;;
esac esac
done done
shift $((OPTIND-1)) echo "kubectl $finalopts --kubeconfig=$HOME/.kube/${CONTEXT}_config"
kubectl $* --kubeconfig=$HOME/.kube/${CONTEXT}_config command kubectl $finalopts --kubeconfig=$HOME/.kube/${CONTEXT}_config
}
function stern {
CONTEXT=gcloud
finalopts=()
while [[ $@ != "" ]] do
case $1 in
-c)
CONTEXT="$2"
shift
shift
;;
--context=*)
CONTEXT="${i#*=}"
shift
;;
*)
finalopts+=($1)
shift
;;
esac
done
echo "stern $finalopts --kubeconfig=$HOME/.kube/${CONTEXT}_config"
command stern $finalopts -t --since 10m --kubeconfig=$HOME/.kube/${CONTEXT}_config
} }
alias kg="k -c qcloud" alias kg="k -c qcloud"
function h() { function h() {