aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-08 00:21:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-08 00:21:22 +1200
commit579b420b53f66a41c66d7aa1312933cd66fa9bb0 (patch)
tree644437a3edccbee07376ec4075dfe19c6c9d506e
parentFix a backdated manual page (diff)
downloaddotfiles-579b420b53f66a41c66d7aa1312933cd66fa9bb0.tar.gz
dotfiles-579b420b53f66a41c66d7aa1312933cd66fa9bb0.zip
Add rgl(1df)
-rw-r--r--README.markdown1
-rwxr-xr-xbin/rgl17
-rw-r--r--man/man1/rgl.1df19
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>