Commit 90d78aae authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Improve shell & vim grepping using wrapper script

~/.shell/bin/grep-auto-exclude - a wrapper around `grep`

The environment variable GREP_EXCLUDE_DIRS can be used to specify any
more space-delimited directories to exclude from recursively grepping,
on top of the known VCS directories.

This wrapper is intended to be used in vim as a grep command:

    set grepprg=~/.shell/bin/grep-auto-exclude\ -n

or as a shell aliases like so:

    alias grep='~/.shell/bin/grep-auto-exclude grep --color=auto -n'

In which case calling `grep FOO -r .` will result in a colourful, numbered
output which does not recurse into VCS directories or any directories
listed in GREP_EXCLUDE_DIRS.
parent 8576e3e8
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
#!/bin/sh
#
# A wrapper around grep commands to help more complex aliases.
#
# Usage:
#   export GREP_EXCLUDE_DIRS='foo bar ...'
#   ~/.shell/bin/grep [grep|fgrep|egrep] [OPTIONS]
#

VCS_DIRS='.bzr .cvs .git .hg .svn'

case "$1" in
	grep|fgrep|egrep) CMD="$1"; shift ;;
	*) CMD=grep ;;
esac

for dir in $VCS_DIRS $GREP_EXCLUDE_DIRS; do
	set -- --exclude-dir="$dir" "$@"
done

exec $CMD "$@"
+3 −3
Original line number Diff line number Diff line
alias ls='ls --color=auto -lh'
alias dir='dir --color=auto'
alias grep='grep --color=auto --exclude-dir={.bzr,.cvs,.git,.hg,.svn} -n'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias grep='~/.shell/bin/grep-auto-exclude grep --color=auto -n'
alias fgrep='~/.shell/bin/grep-auto-exclude fgrep --color=auto -n'
alias egrep='~/.shell/bin/grep-auto-exclude egrep --color=auto -n'
+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@ nmap <silent>th :set hlsearch!<CR>



" === GREPPING ===
set grepprg=~/.shell/bin/grep-auto-exclude\ -n


" === MISC COMMANDS ===

" A little home-made command for renaming the current file