diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-04 12:13:23 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-04 12:13:23 +1200 |
commit | 45f259ccb69972c2c3848cd6970e2244a395d464 (patch) | |
tree | e7bdacacbc34a91d7ab172a4d746249bc74eeccf /bin/clwr | |
parent | Make mktd(1) call in rndl(1) only if needed (diff) | |
download | dotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.tar.gz dotfiles-45f259ccb69972c2c3848cd6970e2244a395d464.zip |
Change clwr(1) to POSIX sh
Diffstat (limited to 'bin/clwr')
-rwxr-xr-x | bin/clwr | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -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 |