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 | |
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
-rwxr-xr-x | bin/clwr | 20 | ||||
-rw-r--r-- | man/man1/clwr.1 | 8 |
2 files changed, 18 insertions, 10 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 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 |