Skip to content

Instantly share code, notes, and snippets.

@rjames86
Created January 12, 2016 05:25

Revisions

  1. Ryan M created this gist Jan 12, 2016.
    47 changes: 47 additions & 0 deletions todos_emacs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    function ga_code_search() {
    # alias todo='ga_code_search "TODO\(`whoami`\)"'
    SCREEN_WIDTH=`stty size | awk '{print $2}'`
    SCREEN_WIDTH=$((SCREEN_WIDTH-4))

    # Given a spooky name so you can alias to whatever you want.
    # (cs for codesearch)

    # AG is WAY faster but requires a binary
    # (try brew install the_silver_searcher)
    AG_SEARCH='ag "$1" | sort -k1 | cat -n | cut -c 1-$SCREEN_WIDTH'

    # egrep is installed everywhere and is the default.
    GREP_SEARCH='egrep -nR "$1" * | sort -k1 | cat -n'

    SEARCH=$AG_SEARCH
    if [ $# -eq 0 ]; then
    echo "Usage: ga_code_search <search> <index_to_edit>"
    echo ""
    echo "Examples:"
    echo " ga_code_search TODO"
    echo " ga_code_search TODO 1"
    echo " ga_code_search \"TODO\\(graham\\)\""
    echo " ga_code_search \"TODO\\(graham\\)\" 4"
    echo ""
    return
    fi

    if [ $# -eq 1 ]; then
    # There are no command line argumnets.
    eval $SEARCH
    else
    # arg one should be a line from the output of above.
    LINE="$SEARCH | sed '$2q;d' | awk -F':' '{print +\$2 \" \" \$1}' | awk -F' ' '{print \$3 \":\" \$1}'"
    # Modify with your editor here.
    emacs `eval $LINE`
    fi
    }

    # Find todo items that are assigned to me.
    alias todo='ga_code_search "TODO\(`whoami`\)"'

    # Find merge conflicts that need to be resolved.
    alias conf='ga_code_search "<<<<<<<<<"'

    # Find anything below your CWD.
    alias ccs='ga_code_search'