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 bash <tab> completion for grunt, add the following line (minus the
13 # leading #, which is the bash comment character) to your ~/.bashrc file:
15 # eval "$(grunt --completion=bash)"
17 # Search the current directory and all parent directories for a gruntfile.
18 function _grunt_gruntfile() {
20 while [[ "$curpath" ]]; do
21 for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
22 if [[ -e "$gruntfile" ]]; then
27 curpath="${curpath%/*}"
32 # Enable bash autocompletion.
33 function _grunt_completions() {
34 # The currently-being-completed word.
35 local cur="${COMP_WORDS[COMP_CWORD]}"
36 # The current gruntfile, if it exists.
37 local gruntfile="$(_grunt_gruntfile)"
38 # The current grunt version, available tasks, options, etc.
39 local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
41 local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
42 local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
43 # Only add -- or - options if the user has started typing -
44 [[ "$cur" == -* ]] && compls="$compls $opts"
45 # Tell complete what stuff to show.
46 COMPREPLY=($(compgen -W "$compls" -- "$cur"))
49 complete -o default -F _grunt_completions grunt