From 0fa396fbcbf055f9975d6e786515c8bcb13af613 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Fri, 17 Jan 2020 17:06:00 -0800 Subject: [PATCH] Add pager_name function to pager.sh --- lib/pager.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/pager.sh b/lib/pager.sh index 516f467..74cc046 100644 --- a/lib/pager.sh +++ b/lib/pager.sh @@ -7,6 +7,7 @@ # ----------------------------------------------------------------------------- # Defaults. +_SCRIPT_PAGER_NAME= SCRIPT_PAGER_CMD=("$PAGER") SCRIPT_PAGER_ARGS=() @@ -29,6 +30,20 @@ fi # ----------------------------------------------------------------------------- +# Gets the pager name. +pager_name() { + if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi + if [[ -z "$_SCRIPT_PAGER_NAME" ]]; then + local output="$("${SCRIPT_PAGER_CMD[0]}" --version 2>&1)" + + if head -n 1 <<< "$output" | grep '^less \d' &>/dev/null; then + _SCRIPT_PAGER_NAME="less" + fi + fi + + echo "$_SCRIPT_PAGER_NAME" +} + # Executes a command or function, and pipes its output to the pager (if exists). # # Returns: The exit code of the command.