From 4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 8 Sep 2016 00:34:37 +1200 Subject: Enhance rgl(1df) with a bit of color and sanity --- bin/rgl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'bin/rgl') 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 -- cgit v1.2.3