diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-10-10 01:59:06 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-10-10 02:02:26 +0200 |
commit | d72448ae0bd6ec2abef5277b38a32547dfe517eb (patch) | |
tree | f5aca57b320909937e7932dc901344efac73f267 | |
parent | 0e23f263df51c2032e6035170d38cf9651ce06c3 (diff) |
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 <alx@kernel.org>
-rwxr-xr-x | bin/ovr | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -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}"; |