Skip to content

Instantly share code, notes, and snippets.

@turadg
Created February 23, 2011 16:28

Revisions

  1. turadg revised this gist Mar 29, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rake.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ function _rake_cache_path() {
    }

    function rake_cache_store() {
    rake -T > "$(_rake_cache_path)"
    rake --tasks --silent > "$(_rake_cache_path)"
    }

    function rake_cache_clear() {
  2. turadg renamed this gist Feb 23, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.eclass → rake.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    # bash completion for rake
    #
    # some code from on Jonathan Palardy's http://technotales.wordpress.com/2009/09/18/rake-completion-cache/
  3. turadg created this gist Feb 23, 2011.
    58 changes: 58 additions & 0 deletions gistfile1.eclass
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@

    # bash completion for rake
    #
    # some code from on Jonathan Palardy's http://technotales.wordpress.com/2009/09/18/rake-completion-cache/
    # and http://pastie.org/217324 found http://ragonrails.com/post/38905212/rake-bash-completion-ftw
    #
    # For details and discussion
    # http://turadg.aleahmad.net/2011/02/bash-completion-for-rake-tasks/
    #
    # INSTALL
    #
    # Place in your bash completions.d and/or source in your .bash_profile
    # If on a Mac with Homebrew, try "brew install bash-completion"
    #
    # USAGE
    #
    # Type 'rake' and hit tab twice to get completions.
    # To clear the cache, run rake_cache_clear() in your shell.
    #

    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 -T > "$(_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