1 | #!/bin/bash
|
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 bash <tab> completion for grunt, add the following line (minus the
|
13 | # leading #, which is the bash comment character) to your ~/.bashrc file:
|
14 | #
|
15 | # eval "$(grunt --completion=bash)"
|
16 |
|
17 | # Search the current directory and all parent directories for a gruntfile.
|
18 | function _grunt_gruntfile() {
|
19 | local curpath="$PWD"
|
20 | while [[ "$curpath" ]]; do
|
21 | for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
|
22 | if [[ -e "$gruntfile" ]]; then
|
23 | echo "$gruntfile"
|
24 | return
|
25 | fi
|
26 | done
|
27 | curpath="${curpath%/*}"
|
28 | done
|
29 | return 1
|
30 | }
|
31 |
|
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)"
|
40 | # Options and tasks.
|
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"))
|
47 | }
|
48 |
|
49 | complete -o default -F _grunt_completions grunt
|