From 7a89c786e004de3d85f58a0931a10e50a3b206f7 Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Mon, 15 Jan 2018 10:25:44 +0700 Subject: [PATCH] Adds ZSH completion Similar to patch set in Nova side [1]. As a Zsh user, I think this feature is necessary. [1] https://review.openstack.org/#/c/34972/ Change-Id: I297db41cb6eb7ecc1e1b0411aea992a5b063b4da --- tools/zun.zsh_completion | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tools/zun.zsh_completion diff --git a/tools/zun.zsh_completion b/tools/zun.zsh_completion new file mode 100644 index 00000000..398d8153 --- /dev/null +++ b/tools/zun.zsh_completion @@ -0,0 +1,29 @@ +#compdef zun + +local -a nbc _zun_opts _zun_flags _zun_opts_exp cur prev + +nbc=(${(ps: :)$(_call_program options "$service bash-completion" 2>/dev/null)}) +_zun_opts=(${nbc:#-*}) +_zun_flags=(${(M)nbc:#-*}) +_zun_opt_exp=${${nbc:#-*}// /|} +cur=$words[CURRENT] +prev=$words[(( CURRENT - 1 ))] + +_checkcomp(){ + for word in $words[@]; do + if [[ -n ${_zun_opts[(r)$word]} ]]; then + return 0 + fi + done + return 1 +} + +echo $_zun_opts[@] |grep --color zun +if [[ "$prev" != "help" ]] && _checkcomp; then + COMPLETION_CACHE=(~/.zunclient/*/*-cache) + cflags=($_zun_flags[@] ${(ps: :)$(cat $COMPLETION_CACHE 2>/dev/null)}) + compadd "$@" -d $cflags[@] +else + compadd "$@" -d $_zun_opts[@] +fi +