Debian Codegraph @

completion/zsh

raw
1 #!/bin/zsh
2
3 # grunt-cli
4 # http://gruntjs.com/
5 #
6 # Copyright (c) 2016 Tyler Kellen, contributors
7 # Licensed under the MIT license.
8 # https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
9
10 # Usage:
11 #
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:
14 #
15 # eval "$(grunt --completion=zsh)"
16
17 # Enable zsh autocompletion.
18 function _grunt_completion() {
19 local completions
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)"
24 # Options and tasks.
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"
29 # Trim whitespace.
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
35 }
36
37 compdef _grunt_completion grunt