aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-04 12:13:23 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-04 12:13:23 +1200
commit45f259ccb69972c2c3848cd6970e2244a395d464 (patch)
treee7bdacacbc34a91d7ab172a4d746249bc74eeccf
parentMake mktd(1) call in rndl(1) only if needed (diff)
downloaddotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.tar.gz
dotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.zip
Change clwr(1) to POSIX sh
-rwxr-xr-xbin/clwr20
-rw-r--r--man/man1/clwr.18
2 files changed, 18 insertions, 10 deletions
diff --git a/bin/clwr b/bin/clwr
index af39276a..dc045e9d 100755
--- a/bin/clwr
+++ b/bin/clwr
@@ -1,16 +1,24 @@
-#!/usr/bin/env bash
+#!/bin/sh
+# Write lines of terminal input into a file, clearing in between each one
self=clwr
-if (($# != 1)) ; then
+
+# Check our inputs for sanity
+if [ "$#" -ne 1 ] ; then
printf >&2 '%s: Need output file\n' "$self"
exit 2
-elif [[ ! -t 0 ]] ; then
+elif ! [ -t 0 ] ; then
printf >&2 '%s: stdin not a terminal\n' "$self"
exit 2
-elif [[ ! -t 1 ]] ; then
+elif ! [ -t 1 ] ; then
printf >&2 '%s: stdout not a terminal\n' "$self"
exit 2
fi
-exec 3>"$1"
-while { clear && IFS= read -er line ; } ; do
+
+# Open a file descriptor onto the output file to save on open(2)/close(2)
+# system calls
+exec 3>"$1" || exit
+
+# Start looping through clearing and accepting lines
+while { tput clear && IFS= read -r line ; } ; do
printf '%s\n' "$line" >&3
done
diff --git a/man/man1/clwr.1 b/man/man1/clwr.1
index 5b5a1eee..ecb29f5c 100644
--- a/man/man1/clwr.1
+++ b/man/man1/clwr.1
@@ -1,15 +1,15 @@
.TH CLWR 1 "August 2016" "Manual page for clwr"
.SH NAME
.B clwr
-\- clear screen, accept Readline line, write line
+\- clear screen, read line from terminal, write line to file
.SH SYNOPSIS
.B clwr
file
.SH DESCRIPTION
.B clwr
-clears the screen, accepts a line of Readline input from stdin, writes it to
-the given file, and loops. This is for use in minimal socket-network programs
-like ii(1), along with clrd(1).
+clears the screen, accepts a line of input from stdin, writes it to the given
+file, and loops. This is for use in minimal socket-network programs like ii(1),
+along with clrd(1).
.SH SEE ALSO
clrd(1), ii(1)
.SH AUTHOR