diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-24 15:35:58 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-24 15:35:58 +1200 |
commit | d6a850bbdd4aaf66aa3db57f90651269952b2f57 (patch) | |
tree | b291da9a45016cd23680cf0307a88ea1d4b1144c /bash/bashrc.d/grep.bash | |
parent | Remove reference to nonexistent unimpaired binds (diff) | |
download | dotfiles-d6a850bbdd4aaf66aa3db57f90651269952b2f57.tar.gz dotfiles-d6a850bbdd4aaf66aa3db57f90651269952b2f57.zip |
Move GREP_OPTIONS building to bashrc
Shouldn't be exported because it changes the behaviour of grep(1), which
might have unwanted side effects in scripts
Diffstat (limited to 'bash/bashrc.d/grep.bash')
-rw-r--r-- | bash/bashrc.d/grep.bash | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash index be201741..a242603d 100644 --- a/bash/bashrc.d/grep.bash +++ b/bash/bashrc.d/grep.bash @@ -1,3 +1,38 @@ +# Store grep(1)'s --help output in a variable +grep_help=$(grep --help 2>/dev/null) + +# Use GREP_OPTIONS to add some useful options to grep(1) calls if applicable +GREP_OPTIONS= +case $grep_help in + *--binary-files*) + GREP_OPTIONS=${GREP_OPTIONS:+$GREP_OPTIONS }'--binary-files=without-match' + ;; +esac +case $grep_help in + *--exclude*) + for exclude in .gitignore .gitmodules ; do + GREP_OPTIONS=${GREP_OPTIONS:+$GREP_OPTIONS }'--exclude='$exclude + done + unset -v exclude + ;; +esac +case $grep_help in + *--exclude-dir*) + for exclude_dir in .cvs .git .hg .svn ; do + GREP_OPTIONS=${GREP_OPTIONS:+$GREP_OPTIONS }'--exclude-dir='$exclude_dir + done + unset -v exclude_dir + ;; +esac + +# We're done parsing grep(1)'s --help output now +unset -v grep_help + +# Export the grep(1) options if we decided on any +if [ -n "$GREP_OPTIONS" ] ; then + export GREP_OPTIONS +fi + # Define function wrapper for grep(1) with --color option if GREP_COLORS is # set; checks that color is available in the terminal within the function if [[ ! -n $GREP_COLORS ]] ; then |