aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/grep.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-08-18 23:44:02 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-08-18 23:44:02 +1200
commitcc9e9501fad1757008e77038191ec8e13ba7ce05 (patch)
treef7d108534e9981861804376c467f4984330ec8ab /bash/bashrc.d/grep.bash
parentUse arithmetic expression for color space tests (diff)
downloaddotfiles-cc9e9501fad1757008e77038191ec8e13ba7ce05.tar.gz
dotfiles-cc9e9501fad1757008e77038191ec8e13ba7ce05.zip
Add some comments to the ls/grep alias functions
Diffstat (limited to 'bash/bashrc.d/grep.bash')
-rw-r--r--bash/bashrc.d/grep.bash15
1 files changed, 15 insertions, 0 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash
index 942bb9af..dcb27781 100644
--- a/bash/bashrc.d/grep.bash
+++ b/bash/bashrc.d/grep.bash
@@ -1,18 +1,33 @@
# Function returns calculated options for grep
__grepopts() {
+
+ # Declare options array
local -a grepopts
+
+ # Snarf the output of `grep --help` into a variable
local grephelp="$(grep --help 2>/dev/null)"
+
+ # Add option to ignore binary files
grepopts[${#grepopts[@]}]='-I'
+
+ # If the --color option is available and we have a terminal that supports
+ # at least eight colors, add --color=auto to the options
local -i colors="$(tput colors)"
if [[ "$grephelp" == *--color* ]] && ((colors >= 8)); then
grepopts[${#grepopts[@]}]='--color=auto'
fi
+
+ # If the --exclude option is available, exclude some VCS files
if [[ "$grephelp" == *--exclude* ]]; then
grepopts[${#grepopts[@]}]='--exclude=.git{,ignore,modules}'
fi
+
+ # If the --exclude option is available, exclude some VCS dirs
if [[ "$grephelp" == *--exclude-dir* ]]; then
grepopts[${#grepopts[@]}]='--exclude-dir=.{cvs,git,hg,svn}'
fi
+
+ # Print the options as a single string, space-delimited
printf -- "${grepopts[*]}"
}