mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-02-14 16:19:12 +01:00
lib: Fix no pager being used when PAGER and BAT_PAGER are unset (#57)
This commit is contained in:
parent
75d66fa352
commit
20cdf5a998
@ -113,10 +113,14 @@ _detect_pager() {
|
|||||||
# 3. Use PAGER
|
# 3. Use PAGER
|
||||||
_configure_pager() {
|
_configure_pager() {
|
||||||
# shellcheck disable=SC2206
|
# shellcheck disable=SC2206
|
||||||
SCRIPT_PAGER_CMD=($PAGER)
|
|
||||||
SCRIPT_PAGER_ARGS=()
|
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
|
if [[ -n "${BAT_PAGER+x}" ]]; then
|
||||||
# [note]: This is intentional.
|
# [note]: This is intentional.
|
||||||
# shellcheck disable=SC2206
|
# shellcheck disable=SC2206
|
||||||
|
@ -10,6 +10,14 @@ use_pager() {
|
|||||||
_detect_pager
|
_detect_pager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use_no_pager() {
|
||||||
|
unset BAT_PAGER
|
||||||
|
unset PAGER
|
||||||
|
|
||||||
|
_configure_pager
|
||||||
|
_detect_pager
|
||||||
|
}
|
||||||
|
|
||||||
use_bat_pager() {
|
use_bat_pager() {
|
||||||
unset PAGER
|
unset PAGER
|
||||||
export BAT_PAGER="$1"
|
export BAT_PAGER="$1"
|
||||||
@ -29,7 +37,9 @@ test:less_detection() {
|
|||||||
test:bat_detection() {
|
test:bat_detection() {
|
||||||
description "Ensure bat is replaced with less as pager"
|
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() {
|
test:less_version() {
|
||||||
@ -88,6 +98,14 @@ test:env_bat_pager() {
|
|||||||
expect_equal "${SCRIPT_PAGER_CMD[2]}" "not_more"
|
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() {
|
test:args_copied_from_pager() {
|
||||||
description "Check that the pager args are correct with PAGER."
|
description "Check that the pager args are correct with PAGER."
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user