mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-03-04 16:31:17 +01:00
Fix pager_name to print name of unknown pagers
This commit is contained in:
parent
49dfb332c1
commit
72b09b4416
10
lib/pager.sh
10
lib/pager.sh
@ -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
|
||||
|
||||
|
@ -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" \
|
||||
|
Loading…
Reference in New Issue
Block a user