mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02: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 $?
|
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).
|
# Returns 0 (true) if the current pager is disabled, otherwise 1 (false).
|
||||||
is_pager_disabled() {
|
is_pager_disabled() {
|
||||||
[[ -z "$(pager_name)" ]]
|
[[ -z "$(pager_name)" ]]
|
||||||
@ -86,9 +92,13 @@ _detect_pager() {
|
|||||||
output1="$(head -n 1 <<<"$output")"
|
output1="$(head -n 1 <<<"$output")"
|
||||||
|
|
||||||
if [[ "$output1" =~ ^less[[:blank:]]([[:digit:]]+) ]]; then
|
if [[ "$output1" =~ ^less[[:blank:]]([[:digit:]]+) ]]; then
|
||||||
# shellcheck disable=SC2001
|
|
||||||
_SCRIPT_PAGER_VERSION="${BASH_REMATCH[1]}"
|
_SCRIPT_PAGER_VERSION="${BASH_REMATCH[1]}"
|
||||||
_SCRIPT_PAGER_NAME="less"
|
_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
|
else
|
||||||
_SCRIPT_PAGER_VERSION=0
|
_SCRIPT_PAGER_VERSION=0
|
||||||
_SCRIPT_PAGER_NAME="$(basename "${SCRIPT_PAGER_CMD[0]}")"
|
_SCRIPT_PAGER_NAME="$(basename "${SCRIPT_PAGER_CMD[0]}")"
|
||||||
@ -114,6 +124,12 @@ _configure_pager() {
|
|||||||
SCRIPT_PAGER_ARGS=()
|
SCRIPT_PAGER_ARGS=()
|
||||||
return
|
return
|
||||||
fi
|
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.
|
# Add arguments for the less pager.
|
||||||
if is_pager_less; then
|
if is_pager_less; then
|
||||||
|
@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
# Gets the current bat version.
|
# Gets the current bat version.
|
||||||
bat_version() {
|
bat_version() {
|
||||||
command "$EXECUTABLE_BAT" --version | cut -d ' ' -f 2
|
if [[ -z "${__BAT_VERSION}" ]]; then
|
||||||
return
|
__BAT_VERSION="$(command "$EXECUTABLE_BAT" --version | cut -d ' ' -f 2)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${__BAT_VERSION}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compares two version strings.
|
# Compares two version strings.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user