diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-08 00:34:37 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-08 00:34:37 +1200 |
commit | 4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f (patch) | |
tree | 16b16f296fe66581cb0d556b4c6ec4fa856db846 /bin/rgl | |
parent | Add rgl(1df) (diff) | |
download | dotfiles-4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f.tar.gz dotfiles-4ea0d491febbc8ec37dda6e51cd4a19e1013ee3f.zip |
Enhance rgl(1df) with a bit of color and sanity
Diffstat (limited to 'bin/rgl')
-rwxr-xr-x | bin/rgl | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -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 |