lib: Fix no pager being used when PAGER and BAT_PAGER are unset (#57)

This commit is contained in:
Ethan P 2021-04-13 12:08:37 -07:00
parent 75d66fa352
commit 20cdf5a998
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 25 additions and 3 deletions

View File

@ -113,10 +113,14 @@ _detect_pager() {
# 3. Use PAGER
_configure_pager() {
# shellcheck disable=SC2206
SCRIPT_PAGER_CMD=($PAGER)
SCRIPT_PAGER_ARGS=()
if [[ -n "${PAGER+x}" ]]; then
SCRIPT_PAGER_CMD=($PAGER)
else
SCRIPT_PAGER_CMD=("less")
fi
# Prefer the bat pager.
# Prefer the BAT_PAGER environment variable.
if [[ -n "${BAT_PAGER+x}" ]]; then
# [note]: This is intentional.
# shellcheck disable=SC2206

View File

@ -10,6 +10,14 @@ use_pager() {
_detect_pager
}
use_no_pager() {
unset BAT_PAGER
unset PAGER
_configure_pager
_detect_pager
}
use_bat_pager() {
unset PAGER
export BAT_PAGER="$1"
@ -29,7 +37,9 @@ test:less_detection() {
test:bat_detection() {
description "Ensure bat is replaced with less as pager"
(use_pager "bat" && expect_equal "$(pager_name)" "less")
use_pager "bat"
expect_equal "$(pager_name)" "less"
expect array_contains "-R" in "${SCRIPT_PAGER_CMD[@]}"
}
test:less_version() {
@ -88,6 +98,14 @@ test:env_bat_pager() {
expect_equal "${SCRIPT_PAGER_CMD[2]}" "not_more"
}
test:env_no_pager() {
description "Check that no PAGER or BAT_PAGER defaults to less"
use_no_pager
expect_equal "${SCRIPT_PAGER_CMD[0]}" "less"
expect array_contains "-R" in "${SCRIPT_PAGER_CMD[@]}"
}
test:args_copied_from_pager() {
description "Check that the pager args are correct with PAGER."