Skip to content

Instantly share code, notes, and snippets.

@aidangrabe
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aidangrabe/61a85f7d83029c7dd29d to your computer and use it in GitHub Desktop.
Save aidangrabe/61a85f7d83029c7dd29d to your computer and use it in GitHub Desktop.
Gulpc bash autocomplete for tasks
#!/bin/bash
#
# Add task auto-complete to gulpc command
# gulpc command can be setup as an alias:
# alias gulpc="coffee -c Gulpfile.coffee; gulp"
# Usage:
# Add this script to your .bashrc / .profile or just source it as
# needed
# You should then be able to type gulpc [TAB] and get a list of suggestions
_gulpc() {
local gulpfile cur prev opts
COMPREPLY=()
# find the gulpfile.coffee
gulpfile="$(find . -maxdepth 1 -iname "gulpfile.coffee")"
# exit if no gulpfile found
if [ -z "$gulpfile" ]; then
return 1
fi
# current typed word
cur="${COMP_WORDS[COMP_CWORD]}"
# previous typed word
prev="${COMP_WORDS[COMP_CWORD-1]}"
# get the list of tasks
# opts=$(node -e "var gulp = require('gulp'); require('./gulpfile'); console.log(Object.keys(gulp.tasks).join(' '));")
opts=$(grep -e '^\s*gulp.task' "${gulpfile}" | awk -F"'|\"" '{print $2}')
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _gulpc gulpc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment