Skip to content

Instantly share code, notes, and snippets.

@spalenza
Created October 15, 2015 19:51
Show Gist options
  • Select an option

  • Save spalenza/2fdb35dce34696efe517 to your computer and use it in GitHub Desktop.

Select an option

Save spalenza/2fdb35dce34696efe517 to your computer and use it in GitHub Desktop.
rake completion
function _rake_cache_path() {
# If in a Rails app, put the cache in the cache dir
# so version control ignores it
if [ -e 'tmp/cache' ]; then
prefix='tmp/cache/'
fi
echo "${prefix}.rake_t_cache"
}
function rake_cache_store() {
rake --tasks --silent > "$(_rake_cache_path)"
}
function rake_cache_clear() {
rm -f .rake_t_cache
rm -f tmp/cache/.rake_t_cache
}
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
function _rakecomplete() {
# error if no Rakefile
if [ ! -e Rakefile ]; then
echo "missing Rakefile"
return 1
fi
# build cache if missing
if [ ! -e "$(_rake_cache_path)" ]; then
rake_cache_store
fi
local tasks=`awk '{print $2}' "$(_rake_cache_path)"`
COMPREPLY=($(compgen -W "${tasks}" -- ${COMP_WORDS[COMP_CWORD]}))
return 0
}
complete -o default -o nospace -F _rakecomplete rake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment