diff options
-rw-r--r-- | README.markdown | 1 | ||||
-rwxr-xr-x | bin/rgl | 17 | ||||
-rw-r--r-- | man/man1/rgl.1df | 19 |
3 files changed, 37 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 211ce5fe..559244a7 100644 --- a/README.markdown +++ b/README.markdown @@ -447,6 +447,7 @@ Installed by the `install-bin` target: * `plmu(1df)` retrieves a list of installed modules from [`plenv`](https://github.com/tokuhirom/plenv), filters out any modules in `~/.plenv/non-cpan-modules`, and updates them all. +* `rgl(1df)` is a very crude interactive `grep(1)` loop. * `shb(1df)` attempts to build shebang lines for scripts from `$PATH`. * `spr(1df)` posts its input to the sprunge.us pastebin. * `sshi(1df)` prints human-readable SSH connection details. diff --git a/bin/rgl b/bin/rgl new file mode 100755 index 00000000..03f1ba71 --- /dev/null +++ b/bin/rgl @@ -0,0 +1,17 @@ +#!/bin/sh +# Read grep(1) patterns from input and search for them in the given files + +# Check the arguments +if [ "$#" -eq 0 ] ; then + printf >&2 'rgl: Need at least one filename\n' + 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 +while { + [ -t 0 ] && printf / + read -r pat +} ; do + grep -- "$pat" "$@" +done diff --git a/man/man1/rgl.1df b/man/man1/rgl.1df new file mode 100644 index 00000000..eb5b2905 --- /dev/null +++ b/man/man1/rgl.1df @@ -0,0 +1,19 @@ +.TH RGL 1df "September 2016" "Manual page for rgl" +.SH NAME +.B rgl +\- search files for patterns read from stdin +.SH SYNOPSIS +.B rgl +file +.br +.B rgl +file1 file2 file3 +.br +.B rgl +file < patterns +.SH DESCRIPTION +.B rgl ("read, grep, loop") searches the files given in its arguments for each +of the patterns given on standard input with grep(1). If it detects its input +is a terminal, it provides a forward slash as a prompt for the next pattern. +.SH AUTHOR +Tom Ryder <tom@sanctum.geek.nz> |