Something went wrong. Try again.
Mirroring: https://github.com/MunifTanjim/scripts.sh
Something went wrong. Try again.
8.9 kB · 312 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313#compdef ncd
__debug() { echo "$@" >> /tmp/ncd_debug}
__ncd_caching_policy() { local -a oldp oldp=( "${1}"(Nmh+12) ) # 12 hours (( ${#oldp} ))}
__ncd_repo_names() { integer ret=1
if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi
local cache_name="_ncd_repo_names"
if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "listing repo names..." _ncd_repo_names=($(ncd list:repo)) _store_cache ${cache_name#_} ${cache_name} fi
_describe -t repos "repo names" _ncd_repo_names \ && ret=0
return ret}
__ncd_dc_containers() { integer ret=1
if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi
local cache_name="_ncd_dc_containers"
if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "reading docker containers..." _ncd_dc_containers=($(ncd list:container)) _store_cache ${cache_name#_} _ncd_dc_containers fi
_describe -t containers "docker containers" _ncd_dc_containers \ && ret=0
return ret}
__ncd_dc_commands() { integer ret=1
if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi
local cache_name="_ncd_dc_commands"
if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "reading ncd dc commands..." _ncd_dc_commands=(${(f)"$(ncd dc --help | sed '1,/Commands:/d' | sed '/^$/,$d' | sed 's/^ //' | sed 's/^\([^ ]*\) */\1:/g')"}) _store_cache ${cache_name#_} _ncd_dc_commands fi
_describe -t commands "${words[2]} commands" _ncd_dc_commands \ && ret=0
return ret}
__ncd_arguments() { integer ret=1
case "${words[1]}" in config) _message "Enter config key" && ret=0 ;; ec2_ip) _message "Enter pattern for EC2 name" && ret=0 ;; aws) local curcontext="${curcontext}" state
_arguments -C \ '1: :->scope' \ '*:: :->args' \ && ret=0
case "${state}" in scope) _ncd_aws_scopes=() _ncd_aws_scopes+=("login" "apigateway" "codeartifact-auth-token") _describe -t scope "scope" _ncd_aws_scopes \ && ret=0 ;; args) case "${words[1]}" in apigateway) local curcontext="${curcontext}" state
_arguments -C \ '1: :->command' \ '*:: :->flags' \ && ret=0
case "${state}" in command) _ncd_aws_apigateway_commands=() _ncd_aws_apigateway_commands+=("get-api-key" "get-usage-plan" "list-usage-plans" "view-usage-plan" "change-usage-plan" "get-usage" "update-usage") _describe -t commands "commands" _ncd_aws_apigateway_commands \ && ret=0 ;; flags) case "${words[1]}" in get-api-key) _arguments \ '--region[AWS region]:region:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; get-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; list-usage-plans) _arguments \ '--region[AWS region]:region:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; view-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; change-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ && ret=0 ;; get-usage) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--start-date[Start date (YYYY-MM-DD)]:start-date:' \ '--end-date[End date (YYYY-MM-DD)]:end-date:' \ '--refresh[Force refresh cache]' \ '--plot[Show usage plot]' \ && ret=0 ;; update-usage) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; esac ;; esac ;; esac ;; esac ;; es) _ncd_es_commands=() _ncd_es_commands+=("aqs") _describe -t commands "commands" _ncd_es_commands \ && ret=0 ;; dc) local curcontext="${curcontext}" state
_arguments -C \ '1: :->command' \ '*: :->argument' \ && ret=0
case "${state}" in command) __ncd_dc_commands && ret=0 ;; argument) _message "Enter arguments for ncd dc ${words[2]}" && ret=0 case "${words[$CURRENT]}" in -*) ;; *) __ncd_dc_containers && ret=0 ;; esac ;; esac ;; git) local curcontext="${curcontext}" state
_arguments -C \ '1: :->command' \ && ret=0
case "${state}" in command) _ncd_git_commands=("default-branch" "pr-sync" "prepare-remote" "rebase" "sync") _describe -t commands "commands" _ncd_git_commands \ && ret=0 ;; esac ;; list) _ncd_list_things=("container" "repo" "repo-window") _describe -t things "things" _ncd_list_things \ && ret=0 ;; k8s) _ncd_k8s_commands=() _ncd_k8s_commands+=("add-context" "current-context") _ncd_k8s_commands+=("create-token" "copy-token") _ncd_k8s_commands+=("exec" "logs") _describe -t commands "commands" _ncd_k8s_commands \ && ret=0 ;; py) _ncd_py_commands=("venv-init" "venv-remove" "try-install") _describe -t commands "commands" _ncd_py_commands \ && ret=0 ;; repo) local curcontext="${curcontext}" state
_arguments -C \ '1: :->name' \ && ret=0
case "${state}" in name) _ncd_repo_windows=($(ncd list:repo-window))
_describe -t repo_windows "Repo Windows" _ncd_repo_windows \ && ret=0
__ncd_repo_names && ret=0 ;; esac ;; esac
return ret}
__ncd_commands() { local -a _ncd_commands=() _ncd_commands+=("on" "off") _ncd_commands+=("git" "list") _ncd_commands+=("dc" "repo") _ncd_commands+=("py" "k8s") _ncd_commands+=("es") _ncd_commands+=("aws") _ncd_commands+=("workspace")
_describe -t ncd-commands "commands" _ncd_commands}
_ncd() { setopt localoptions typesetsilent
local context curcontext="${curcontext}" state state_descr line local -A opt_args integer ret=1
_arguments -C \ '1: :->command' \ '*:: :->argument' \ && ret=0
case "${state}" in command) __ncd_commands && ret=0 ;; argument) curcontext="${curcontext%:*}:${words[1]}:" __ncd_arguments && ret=0 ;; esac
return ret}
_ncd $@