aboutsummaryrefslogtreecommitdiff
path: root/bin
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 /bin
parentMake mktd(1) call in rndl(1) only if needed (diff)
downloaddotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.tar.gz
dotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.zip
Change clwr(1) to POSIX sh
Diffstat (limited to 'bin')
-rwxr-xr-xbin/clwr20
1 files changed, 14 insertions, 6 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