aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/grep.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-06-24 15:53:29 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-06-24 15:53:29 +1200
commit0742d98d721e9f791f8bceea11d575792ce9ff61 (patch)
tree855ab0359477d8f4a76ee02b241d867d7e446e09 /bash/bashrc.d/grep.bash
parentRemove GREP_OPTIONS export (diff)
downloaddotfiles-0742d98d721e9f791f8bceea11d575792ce9ff61.tar.gz
dotfiles-0742d98d721e9f791f8bceea11d575792ce9ff61.zip
Use Bashy syntax to build GREP_OPTIONS more nicely
Diffstat (limited to 'bash/bashrc.d/grep.bash')
-rw-r--r--bash/bashrc.d/grep.bash34
1 files changed, 12 insertions, 22 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash
index 277bc4cd..3605a925 100644
--- a/bash/bashrc.d/grep.bash
+++ b/bash/bashrc.d/grep.bash
@@ -2,28 +2,18 @@
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
+declare -a grep_options
+if [[ $grep_help == *--binary-files* ]] ; then
+ grep_options=("${grep_options[@]}" --binary-files=without-match)
+fi
+if [[ $grep_help == *--exclude* ]] ; then
+ grep_options=("${grep_options[@]}" --exclude={.gitignore,.gitmodules})
+fi
+if [[ $grep_help == *--exclude-dir* ]] ; then
+ grep_options=("${grep_options[@]}" --exclude-dir={.cvs,.git,.hg,.svn})
+fi
+GREP_OPTIONS=${grep_options[*]}
+unset -v grep_options
# We're done parsing grep(1)'s --help output now
unset -v grep_help