Last active
August 29, 2015 14:27
-
-
Save aidangrabe/61a85f7d83029c7dd29d to your computer and use it in GitHub Desktop.
Gulpc bash autocomplete for tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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