Skip to contentSkip to conversation

Only invoke pager if there's any output

PATCH Applied Dan Holmsand 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 4/6 Only invoke pager if there's any output

This avoids annoying empty "less" window if there's no output from cg-diff, for example.

---

 cg-Xlib |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
cg-Xlib +5 -1
@@ -22,7 +22,11 @@ usage() {
 }
 
 pager () {
-	LESS="R$LESS" ${PAGER:-less} $PAGER_FLAGS
+	# Invoke $PAGER if there is any output
+	local line
+	if read -r line; then
+		( echo "$line"; cat ) | LESS="-R $LESS" ${PAGER:-less}
+	fi
 }
 
 mktemp () {