From 276176cd0146e6017c57cffdf099def78ecfac24 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 5 Mar 2017 23:03:36 +0100 Subject: [PATCH] subcommand: Use pager for man output if possible. The manual can be much longer than one page, and it is easy to tell whether stdout is associated with a terminal. The new _gsu_isatty() takes care of that. It has been verified to work on FreeBSD, NetBSD and Linux. --- subcommand | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/subcommand b/subcommand index 71f0614..ab6ae8a 100644 --- a/subcommand +++ b/subcommand @@ -267,22 +267,35 @@ com_prefs() done } +_gsu_isatty() +{( + exec 3<&1 + stty 0<&3 &> /dev/null +)} + complete_prefs() { gsu_complete_options "$com_prefs_options" "$@" } -_gsu_man_txt=" +_gsu_man_txt=' Print the manual. -Usage: man" +Usage: man + +If stdout associated with a terminal device, output is piped to +$PAGER. If $PAGER is unset, less(1) is assumed. +' com_man() { local equal_signs="==================================================" local minus_signs="--------------------------------------------------" - local com num + local com num pager='cat' + _gsu_isatty && pager="${PAGER:-less}" + [[ "$pager" == 'less' ]] && export LESS=${LESS-RI} + { echo "$gsu_name (_${gsu_banner_txt}_) manual" echo "${equal_signs:0:${#gsu_name} + ${#gsu_banner_txt} + 16}" echo @@ -310,6 +323,7 @@ com_man() $0 help $com echo done + } | $pager ret=$GSU_SUCCESS } -- 2.39.5