mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-11-07 08:14:02 +01:00
lib: Use 'less' as pager instead of 'bat'
This commit is contained in:
parent
cae57be87b
commit
4f0b961d12
18
lib/pager.sh
18
lib/pager.sh
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user