Skip to content

Instantly share code, notes, and snippets.

@greuze
Created June 4, 2015 15:31
Show Gist options
  • Save greuze/9249c362d630ef465bb6 to your computer and use it in GitHub Desktop.
Save greuze/9249c362d630ef465bb6 to your computer and use it in GitHub Desktop.
Autocomplete grunt task if Gruntfile.js is present
# Create function that will run when a certain phrase is typed in terminal
# and tab key is pressed twice
_grunt_complete()
{
# fill local variable with a list of completions
local COMPLETES=`grep -s 'grunt\.registerTask' Gruntfile.js | sed "s/\s*grunt.registerTask('\([^']*\)',.*$/\1/g"`
# we put the completions into $COMPREPLY using compgen
COMPREPLY=( $(compgen -W "$COMPLETES" -- ${COMP_WORDS[COMP_CWORD]}) )
return 0
}
# get completions for command 'grunt' from function '_grunt_complete()'
complete -F _grunt_complete grunt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment