From d72448ae0bd6ec2abef5277b38a32547dfe517eb Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 10 Oct 2023 01:59:06 +0200 Subject: bin/ovr: -n, --lines: Add option to control permanent lines This was previously accepted as a positional argument, but an option is more conventional. Use the same option name as tail(1), since we just pass it directly to tail(1). Rename the old $lines variable to $permanent, to avoid confusion. Signed-off-by: Alejandro Colomar --- bin/ovr | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/ovr b/bin/ovr index f5c4feb..349bca3 100755 --- a/bin/ovr +++ b/bin/ovr @@ -2,14 +2,43 @@ trap '' INT; + +err() +{ + >&2 echo "$(basename "$0"): error: $*"; + exit 1; +} + + +n=1 +while test $# -ge 1; do + case "$1" in + -n | --lines) + if test $# -lt 2; then + err "$1: Missing option argument."; + fi; + n="$2"; + shift; + ;; + -*) + err "$1: Unknown option."; + ;; + *) + err "$1: Unknown argument."; + ;; + esac; + shift; +done; + + +permanent=; + enter() { setterm --linewrap off; tput smcup; } >/dev/tty; leave() { setterm --linewrap on; tput rmcup; } >/dev/tty; trap leave QUIT TERM; -lines=; -n="${1:-1}"; enter; -lines="$(tee /dev/tty | tail -n "$n"; echo x)"; +permanent="$(tee /dev/tty | tail -n "$n"; echo x)"; leave; -printf '%s' "${lines%x}"; +printf '%s' "${permanent%x}"; -- cgit v1.2.3