lib: Use 'less' as pager instead of 'bat'

This commit is contained in:
Ethan P 2021-04-10 12:24:41 -07:00
parent cae57be87b
commit 4f0b961d12
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 22 additions and 3 deletions

View File

@ -12,6 +12,12 @@ is_pager_less() {
return $?
}
# Returns 0 (true) if the current pager is bat, otherwise 1 (false).
is_pager_bat() {
[[ "$(pager_name)" = "bat" ]]
return $?
}
# Returns 0 (true) if the current pager is disabled, otherwise 1 (false).
is_pager_disabled() {
[[ -z "$(pager_name)" ]]
@ -86,9 +92,13 @@ _detect_pager() {
output1="$(head -n 1 <<<"$output")"
if [[ "$output1" =~ ^less[[:blank:]]([[:digit:]]+) ]]; then
# shellcheck disable=SC2001
_SCRIPT_PAGER_VERSION="${BASH_REMATCH[1]}"
_SCRIPT_PAGER_NAME="less"
elif [[ "$output1" =~ ^bat(cat)?[[:blank:]]([[:digit:]]+) ]]; then
# shellcheck disable=SC2034
__BAT_VERSION="${BASH_REMATCH[2]}"
_SCRIPT_PAGER_VERSION="${BASH_REMATCH[2]}"
_SCRIPT_PAGER_NAME="bat"
else
_SCRIPT_PAGER_VERSION=0
_SCRIPT_PAGER_NAME="$(basename "${SCRIPT_PAGER_CMD[0]}")"
@ -114,6 +124,12 @@ _configure_pager() {
SCRIPT_PAGER_ARGS=()
return
fi
# If the pager is bat, use less instead.
if is_pager_bat; then
SCRIPT_PAGER_CMD=("less")
SCRIPT_PAGER_ARGS=()
fi
# Add arguments for the less pager.
if is_pager_less; then

View File

@ -8,8 +8,11 @@
# Gets the current bat version.
bat_version() {
command "$EXECUTABLE_BAT" --version | cut -d ' ' -f 2
return
if [[ -z "${__BAT_VERSION}" ]]; then
__BAT_VERSION="$(command "$EXECUTABLE_BAT" --version | cut -d ' ' -f 2)"
fi
echo "${__BAT_VERSION}"
}
# Compares two version strings.