update kcontext autocomplete

This commit is contained in:
2023-10-13 20:15:41 +08:00
parent 811b56705c
commit 6d1b390256
2 changed files with 110 additions and 82 deletions

View File

@@ -6,13 +6,11 @@ if [ $? -ne 0 ]; then
return 1
fi
complete -W "k8s docker s3-arch" kcontext
function kcontext {
case $1 in
k8s) shift; kcontext-k8s "$@" ;;
docker) shift; kcontext-docker "$@" ;;
s3-arch) shift; kcontext-s3-arch "$@" ;;
k8s) shift; _kcontext-k8s "$@" ;;
docker) shift; _kcontext-docker "$@" ;;
s3-arch) shift; _kcontext-s3-arch "$@" ;;
*)
__func_head "k8s ..."
__func_help "s3-arch ..."
@@ -23,7 +21,37 @@ function kcontext {
return $?
}
function kcontext-k8s {
function _kcontext {
local CUR=${COMP_WORDS[COMP_CWORD]}
local SCOPE=${COMP_WORDS[COMP_CWORD-1]}
local t
COMPREPLY=()
case "$SCOPE" in
kcontext)
COMPREPLY=( $(compgen -W "k8s docker s3-arch" -- $CUR) )
;;
k8s|s3-arch)
COMPREPLY=( $(compgen -W "use del list save" -- $CUR) )
return
;;
use|del)
SCOPE=${COMP_WORDS[COMP_CWORD-2]}
;;
esac
case "$SCOPE" in
k8s|s3-arch)
COMPREPLY=( $(compgen -W "$( kcontext $SCOPE list )" -- $CUR) )
;;
esac
}
complete -F _kcontext kcontext
function _kcontext-k8s {
local _NAME _CONF
case $1 in
list)
@@ -107,7 +135,7 @@ function kcontext-k8s {
return 1
}
function kcontext-s3-arch {
function _kcontext-s3-arch {
local _NAME _CONFIRM _URL _AUTH
case $1 in
list)