diff --git a/lib/pager.sh b/lib/pager.sh index bdb060c..826b0d8 100644 --- a/lib/pager.sh +++ b/lib/pager.sh @@ -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 diff --git a/test/suite/lib_pager.sh b/test/suite/lib_pager.sh index 0ee7d5a..03ef053 100644 --- a/test/suite/lib_pager.sh +++ b/test/suite/lib_pager.sh @@ -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."