mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-11-07 16:24:06 +01:00
Add pager_name function to pager.sh
This commit is contained in:
parent
c80d107d1c
commit
0fa396fbcb
15
lib/pager.sh
15
lib/pager.sh
@ -7,6 +7,7 @@
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# Defaults.
|
# Defaults.
|
||||||
|
_SCRIPT_PAGER_NAME=
|
||||||
SCRIPT_PAGER_CMD=("$PAGER")
|
SCRIPT_PAGER_CMD=("$PAGER")
|
||||||
SCRIPT_PAGER_ARGS=()
|
SCRIPT_PAGER_ARGS=()
|
||||||
|
|
||||||
@ -29,6 +30,20 @@ fi
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Gets the pager name.
|
||||||
|
pager_name() {
|
||||||
|
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
|
||||||
|
if [[ -z "$_SCRIPT_PAGER_NAME" ]]; then
|
||||||
|
local output="$("${SCRIPT_PAGER_CMD[0]}" --version 2>&1)"
|
||||||
|
|
||||||
|
if head -n 1 <<< "$output" | grep '^less \d' &>/dev/null; then
|
||||||
|
_SCRIPT_PAGER_NAME="less"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$_SCRIPT_PAGER_NAME"
|
||||||
|
}
|
||||||
|
|
||||||
# Executes a command or function, and pipes its output to the pager (if exists).
|
# Executes a command or function, and pipes its output to the pager (if exists).
|
||||||
#
|
#
|
||||||
# Returns: The exit code of the command.
|
# Returns: The exit code of the command.
|
||||||
|
Loading…
Reference in New Issue
Block a user