mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02: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
|
# 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() {
|
is_pager_less() {
|
||||||
[[ "$(pager_name)" = "less" ]]
|
[[ "$(pager_name)" = "less" ]]
|
||||||
return $?
|
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.
|
# Gets the name of the pager command.
|
||||||
pager_name() {
|
pager_name() {
|
||||||
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
|
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
|
if head -n 1 <<< "$output" | grep '^less \d' &>/dev/null; then
|
||||||
_SCRIPT_PAGER_NAME="less"
|
_SCRIPT_PAGER_NAME="less"
|
||||||
|
else
|
||||||
|
_SCRIPT_PAGER_NAME="$(basename "${SCRIPT_PAGER_CMD[0]}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ if "$OPT_SEARCH_PATTERN"; then
|
|||||||
else
|
else
|
||||||
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
||||||
fi
|
fi
|
||||||
elif [[ -z "$(pager_name)" ]]; then
|
elif is_pager_disabled; then
|
||||||
print_error "$(
|
print_error "$(
|
||||||
echo "The -p/--search-pattern option requires a pager, but" \
|
echo "The -p/--search-pattern option requires a pager, but" \
|
||||||
"the pager was explicitly disabled by \$BAT_PAGER or the" \
|
"the pager was explicitly disabled by \$BAT_PAGER or the" \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user