diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:06:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:46:47 +1200 |
commit | c8ab406749124d2e762ad5cf53963070113afd0f (patch) | |
tree | 54c9721a06957ebe7098a211eea803b0230c0f5d /bin/rgl.sh | |
parent | Handle POSIX correctness in ~/.bash_profile (diff) | |
download | dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip |
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/rgl.sh')
-rw-r--r-- | bin/rgl.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/bin/rgl.sh b/bin/rgl.sh new file mode 100644 index 00000000..630d38b6 --- /dev/null +++ b/bin/rgl.sh @@ -0,0 +1,34 @@ +# 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 '%s: Need at least one filename\n' "$self" + exit 2 +fi + +# Iterate over the patterns and search for each one +while { + + # 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 setaf 1 0 0 || tput AF 1 || tput AF 1 0 0 + 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 + +# Print a newline if this was a terminal to clear the prompt +if [ -t 0 ] ; then + printf '\n' +fi |