6 # Copyright (c) 2016 Tyler Kellen, contributors
7 # Licensed under the MIT license.
8 # https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
12 # To enable zsh <tab> completion for grunt, add the following line (minus the
13 # leading #, which is the zsh comment character) to your ~/.zshrc file:
15 # eval "$(grunt --completion=zsh)"
17 # Enable zsh autocompletion.
18 function _grunt_completion() {
20 # The currently-being-completed word.
21 local cur="${words[@]}"
22 # The current grunt version, available tasks, options, etc.
23 local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
25 local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
26 local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
27 # Only add -- or - options if the user has started typing -
28 [[ "$cur" == -* ]] && compls="$compls $opts"
30 compls=$(echo "$compls" | sed -e 's/^ *//g' -e 's/ *$//g')
31 # Turn compls into an array to of completions.
32 completions=(${=compls})
33 # Tell complete what stuff to show.
34 compadd -- $completions
37 compdef _grunt_completion grunt