Created
October 2, 2012 22:11
-
-
Save Hainish/3823640 to your computer and use it in GitHub Desktop.
rake bash completion
This file contains hidden or 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
# bash completion for rake | |
# Installation: cat rake_completion.sh >> ~/.bashrc | |
# Or, maybe: cat rake_completion.sh > /etc/bash_completion.d/rake | |
# checksecs is the number of seconds between checking for new rake tasks | |
checksecs=600 | |
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} | |
if [[ "`which md5`" != "" ]]; then | |
UID_BIN="md5" | |
elif [[ "`which md5sum`" != "" ]]; then | |
UID_BIN="md5sum" | |
else | |
UID_BIN="base64" | |
fi | |
_output_cache_rakefile(){ | |
local cachefile=$1 | |
date +"%s" > "$cachefile" | |
rake -T 2>/dev/null | cut -d" " -f2 >> "$cachefile" | |
} | |
_check_rakefile() { | |
if [ ! -e Rakefile ]; then | |
return | |
fi | |
local cachefile=/tmp/rake_completion_`echo $PWD | $UID_BIN | cut -d" " -f1` | |
if [ ! -e "$cachefile" ]; then | |
_output_cache_rakefile $cachefile | |
else | |
local timestamp_diff=`expr \`date +"%s"\` - \`cat $cachefile | head -n 1\`` | |
if [ $timestamp_diff -gt $checksecs ]; then | |
rm $cachefile | |
_output_cache_rakefile $cachefile | |
fi | |
fi | |
local tasks=$(tail -n +2 $cachefile) | |
COMPREPLY=( $(compgen -W "${tasks}" -- "${COMP_WORDS[$COMP_CWORD]}") ) | |
} | |
complete -F _check_rakefile -o default rake |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment