aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown2
-rwxr-xr-xbin/pit17
-rw-r--r--man/man1/pit.122
3 files changed, 41 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index de51573b..02dea743 100644
--- a/README.markdown
+++ b/README.markdown
@@ -312,6 +312,8 @@ Installed by the `install-bin` target:
* `jfcd(1)` watches a directory for changes and runs `jfc(1)` if it sees any.
* `maybe(1)` is like `true(1)` or `false(1)`; given a probability of success,
it exits with success or failure. Good for quick tests.
+* `pit(1)` runs its input through a pager if its standard output looks like a
+ terminal.
* `plmu(1)` 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.
diff --git a/bin/pit b/bin/pit
new file mode 100755
index 00000000..f91be680
--- /dev/null
+++ b/bin/pit
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# If no arguments, we'll use stdin
+if [ "$#" -eq 0 ] ; then
+ set /dev/stdin
+fi
+
+# If output seems to be to a terminal, try to run input through a pager of some
+# sort; we'll fall back on more(1) to be POSIX-ish
+if [ -t 1 ] ; then
+ "${PAGER:-more}" -- "$@"
+
+# Otherwise, just run it through with cat(1); a good pager does this anyway,
+# provided it actually exists
+else
+ cat -- "$@"
+fi
diff --git a/man/man1/pit.1 b/man/man1/pit.1
new file mode 100644
index 00000000..34a00aff
--- /dev/null
+++ b/man/man1/pit.1
@@ -0,0 +1,22 @@
+.TH PIT 1 "July 2016" "Manual page for pit"
+.SH NAME
+.B pit
+\- show arguments or output in a pager if stdout looks like a terminal
+.SH SYNOPSIS
+.B pit
+file
+.br
+.B pit
+file1 file2 file3
+.br
+command |
+.B pit
+.SH DESCRIPTION
+.B pit
+shows the contents of the files given as arguments in a pager if its standard
+output looks to be a terminal; otherwise it writes them to stdout.
+.P
+It checks for the PAGER environment variable, and otherwise falls back on
+more(1).
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>