aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-05-30 23:56:54 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-05-30 23:56:54 +1200
commitd20cb23998c672fea3ef344d836102a781517c80 (patch)
treebbec18590b578f7eee131203bf689e0704602df9 /sh
parentRemove a few notes about ~/.profile (diff)
downloaddotfiles-d20cb23998c672fea3ef344d836102a781517c80.tar.gz
dotfiles-d20cb23998c672fea3ef344d836102a781517c80.zip
Overhaul grep(1) and ls(1) options and wrappers
Diffstat (limited to 'sh')
-rw-r--r--sh/profile.d/grep.sh38
-rw-r--r--sh/profile.d/ls.sh26
2 files changed, 56 insertions, 8 deletions
diff --git a/sh/profile.d/grep.sh b/sh/profile.d/grep.sh
new file mode 100644
index 00000000..e83d6268
--- /dev/null
+++ b/sh/profile.d/grep.sh
@@ -0,0 +1,38 @@
+# Store grep(1)'s --help output in a variable
+grep_help=$(grep --help 2>/dev/null)
+
+# Define and store appropriate colors for grep(1) if applicable
+case $grep_help in
+ *--color*)
+ GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36'
+ export GREP_COLORS
+ ;;
+esac
+
+# Use GREP_OPTIONS to add some useful --exclude and --exclude-dir options to
+# grep(1) calls if applicable
+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
+
diff --git a/sh/profile.d/ls.sh b/sh/profile.d/ls.sh
index 25fe4777..3ecaa5fd 100644
--- a/sh/profile.d/ls.sh
+++ b/sh/profile.d/ls.sh
@@ -1,9 +1,19 @@
-# Define and store appropriate colors for ls
-if command -v dircolors >/dev/null 2>&1 ; then
- if [ -r "$HOME"/.dircolors ] ; then
- eval "$(dircolors --sh -- "$HOME"/.dircolors)"
- else
- eval "$(dircolors --sh)"
- fi
-fi
+# Store ls(1)'s --help output in a variable
+lshelp=$(ls --help 2>/dev/null)
+
+# Define and store appropriate colors for ls(1) if applicable
+case $lshelp in
+ *--color*)
+ if command -v dircolors >/dev/null 2>&1 ; then
+ if [ -r "$HOME"/.dircolors ] ; then
+ eval "$(dircolors --sh -- "$HOME"/.dircolors)"
+ else
+ eval "$(dircolors --sh)"
+ fi
+ fi
+ ;;
+esac
+
+# We're done parsing ls(1)'s --help output now
+unset -v lshelp