Add pager_name function to pager.sh

This commit is contained in:
Ethan P 2020-01-17 17:06:00 -08:00
parent c80d107d1c
commit 0fa396fbcb
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -7,6 +7,7 @@
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Defaults. # Defaults.
_SCRIPT_PAGER_NAME=
SCRIPT_PAGER_CMD=("$PAGER") SCRIPT_PAGER_CMD=("$PAGER")
SCRIPT_PAGER_ARGS=() 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). # Executes a command or function, and pipes its output to the pager (if exists).
# #
# Returns: The exit code of the command. # Returns: The exit code of the command.