aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-08 00:34:37 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-08 00:34:37 +1200
commit4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f (patch)
tree16b16f296fe66581cb0d556b4c6ec4fa856db846 /bin
parentAdd rgl(1df) (diff)
downloaddotfiles-4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f.tar.gz
dotfiles-4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f.zip
Enhance rgl(1df) with a bit of color and sanity
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rgl23
1 files changed, 18 insertions, 5 deletions
diff --git a/bin/rgl b/bin/rgl
index 03f1ba71..4f783d9d 100755
--- a/bin/rgl
+++ b/bin/rgl
@@ -1,17 +1,30 @@
#!/bin/sh
# Read grep(1) patterns from input and search for them in the given files
+self=rgl
# Check the arguments
if [ "$#" -eq 0 ] ; then
- printf >&2 'rgl: Need at least one filename\n'
+ printf >&2 '%s: Need at least one filename\n' "$self"
exit 2
fi
-# Iterate over the patterns and search for each one; if the input is a terminal
-# include a slash prompt for the next pattern
+# Iterate over the patterns and search for each one
while {
- [ -t 0 ] && printf /
- read -r pat
+
+ # If the input is a terminal, print a slash prompt for the next pattern;
+ # try to print it in bold red, too, but discard stderr if we can't
+ if [ -t 0 ] ; then
+ tput setaf 1 || tput AF 1
+ tput bold || tput md
+ printf '%s/' "$self"
+ tput sgr0 || tput me
+ fi 2>/dev/null
+
+ # Read the pattern
+ IFS= read -r pat
+
} ; do
+
+ # Run grep(1) with the read pattern over the arguments
grep -- "$pat" "$@"
done