| 1 |
# grunt-cli |
| 2 |
# http://gruntjs.com/ |
| 3 |
# |
| 4 |
# Copyright (c) 2016 Tyler Kellen, contributors |
| 5 |
# Licensed under the MIT license. |
| 6 |
# https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT |
| 7 |
|
| 8 |
# Usage: |
| 9 |
# |
| 10 |
# To enable bash <tab> completion for grunt, add the following line (minus the |
| 11 |
# leading #, which is the bash comment character) to your ~/.bashrc file: |
| 12 |
# |
| 13 |
# eval "$(grunt --completion=bash)" |
| 14 |
|
| 15 |
# Search the current directory and all parent directories for a gruntfile. |
| 16 |
function _grunt_gruntfile() { |
| 17 |
local curpath="$PWD" |
| 18 |
while [[ "$curpath" ]]; do |
| 19 |
for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do |
| 20 |
if [[ -e "$gruntfile" ]]; then |
| 21 |
echo "$gruntfile" |
| 22 |
return |
| 23 |
fi |
| 24 |
done |
| 25 |
curpath="${curpath%/*}" |
| 26 |
done |
| 27 |
return 1 |
| 28 |
} |
| 29 |
|
| 30 |
# Enable bash autocompletion. |
| 31 |
function _grunt_completions() { |
| 32 |
# The currently-being-completed word. |
| 33 |
local cur="${COMP_WORDS[COMP_CWORD]}" |
| 34 |
# The current gruntfile, if it exists. |
| 35 |
local gruntfile="$(_grunt_gruntfile)" |
| 36 |
# The current grunt version, available tasks, options, etc. |
| 37 |
local gruntinfo="$(grunt --version --verbose 2>/dev/null)" |
| 38 |
# Options and tasks. |
| 39 |
local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')" |
| 40 |
local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')" |
| 41 |
# Only add -- or - options if the user has started typing - |
| 42 |
[[ "$cur" == -* ]] && compls="$compls $opts" |
| 43 |
# Tell complete what stuff to show. |
| 44 |
COMPREPLY=($(compgen -W "$compls" -- "$cur")) |
| 45 |
} |
| 46 |
|
| 47 |
complete -o default -F _grunt_completions grunt |