completions/cs.bash in cloudstack-cli-0.8.0 vs completions/cs.bash in cloudstack-cli-0.8.1

- old
+ new

@@ -15,23 +15,27 @@ # eval "$(cs completion --shell=bash)" _cs() { COMPREPLY=() local word="${COMP_WORDS[COMP_CWORD]}" + # list available base commands if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "$(cs help | grep cs | cut -d ' ' -f4)" -- "$word") ) else local words=("${COMP_WORDS[@]}") - if [ $(echo ${words[@]} | wc -w) -eq 2 ]; then - COMPREPLY=( $(compgen -W "$(${words[@]} help | grep cs | cut -d ' ' -f5)" -- "$word") ) - fi - if [ $(echo ${words[@]} | wc -w) -ge 3 ]; then + # ignore commands which contain 'help' + if [[ "${words[@]}" == *help* ]]; then + COMPREPLY=( $(compgen -W '' -- "$word") ) + # search for subcommand + elif [[ "$word" != -* ]] && [ -n "$word" ]; then local cp1=$(echo ${words[@]} | cut -d ' ' -f1-2) + COMPREPLY=( $(compgen -W "$($cp1 help | grep cs | cut -d ' ' -f5)" -- "$word") ) + # list options for the subcommand + elif [[ "$word" =~ -* ]] && [ $(echo ${words[@]} | wc -w) -gt 2 ]; then + local cp1=$(echo ${words[@]} | cut -d ' ' -f1-2) local cp2=$(echo ${words[@]} | cut -d ' ' -f3) - if [ "$cp2" != "help" ]; then - local cp3=$($cp1 help $cp2) - COMPREPLY=( $(compgen -W "$(echo $cp3 | awk 'NR>1{print $1}' RS=[ FS='\=')" -- "$word") ) - fi + local cp3=$($cp1 help $cp2 2>/dev/null) + COMPREPLY=( $(compgen -W "$(echo $cp3 | awk 'NR>1{print $1}' RS=[ FS='\=')" -- "$word") ) fi fi } complete -F _cs cs \ No newline at end of file