Last active
October 16, 2022 13:11
-
-
Save for2ando/c052d63b3d0870935f022c0dc556b71b to your computer and use it in GitHub Desktop.
output files using $PAGER if the number of lines is grater or equal than $LINES, or output using cat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pname=$(basename "$0") | |
while true; do | |
case "$1" in | |
-l) lines="$2"; shift 2;; | |
-*) echo "$pname: '$1': no such option.">&2; shift;; | |
*) break;; | |
esac | |
done | |
test -z "$lines" && lines=$(tput lines) | |
test $# -le 0 && set -- - | |
buffer=$(mktemp -q -t "$pname.XXXXXXXX") | |
trap 'rm -r "$buffer"' 1 2 3 15 EXIT | |
cat "$@" >"$buffer" | |
if [ $(cat "$buffer" | wc -l) -lt $lines ]; then | |
cat "$buffer" | |
else | |
cat "$buffer" | ${PAGER:-less} | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Makefile | |
XPAGER = $(shell which pageless || echo $${PAGER:-less}) | |
output: | |
cat Contents.txt | $(XPAGER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment