Fix pager_name to print name of unknown pagers

This commit is contained in:
Ethan P 2020-01-17 20:49:14 -08:00
parent 49dfb332c1
commit 72b09b4416
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 10 additions and 2 deletions

View File

@ -6,12 +6,18 @@
# Issues: https://github.com/eth-p/bat-extras/issues
# -----------------------------------------------------------------------------
# Returns 0 (true) if the current script pager is less, otherwise 1 (false)
# Returns 0 (true) if the current pager is less, otherwise 1 (false)
is_pager_less() {
[[ "$(pager_name)" = "less" ]]
return $?
}
# Returns 0 (true) if the current pager is disabled, otherwise 1 (false)
is_pager_disabled() {
[[ -z "$(pager_name)" ]]
return $?
}
# Gets the name of the pager command.
pager_name() {
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
@ -20,6 +26,8 @@ pager_name() {
if head -n 1 <<< "$output" | grep '^less \d' &>/dev/null; then
_SCRIPT_PAGER_NAME="less"
else
_SCRIPT_PAGER_NAME="$(basename "${SCRIPT_PAGER_CMD[0]}")"
fi
fi

View File

@ -151,7 +151,7 @@ if "$OPT_SEARCH_PATTERN"; then
else
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
fi
elif [[ -z "$(pager_name)" ]]; then
elif is_pager_disabled; then
print_error "$(
echo "The -p/--search-pattern option requires a pager, but" \
"the pager was explicitly disabled by \$BAT_PAGER or the" \