Merge branch 'master' into search-pattern

This commit is contained in:
Ethan P 2020-01-17 20:30:43 -08:00
commit 63a9929592
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
3 changed files with 18 additions and 7 deletions

View File

@ -8,12 +8,22 @@
# Returns 0 (true) if the current script pager is less, otherwise 1 (false)
is_pager_less() {
[[ "$(get_pager)" = "less" ]]
[[ "$(pager_name)" = "less" ]]
return $?
}
# Echos the name of the pager command
get_pager() {
echo "$(basename "${SCRIPT_PAGER_CMD[0]}")"
# Gets the name of the pager command.
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).
@ -52,7 +62,7 @@ SCRIPT_PAGER_CMD=("$PAGER")
SCRIPT_PAGER_ARGS=()
# Add arguments for the less pager.
if is_pager_less "$(basename "${SCRIPT_PAGER_CMD[0]}")"; then
if is_pager_less; then
SCRIPT_PAGER_ARGS=(-R)
fi
@ -67,3 +77,4 @@ if ! [[ -t 1 ]]; then
SCRIPT_PAGER_CMD=()
SCRIPT_PAGER_ARGS=()
fi

View File

@ -151,8 +151,8 @@ if [[ "$OPT_SEARCH_PATTERN" ]]; then
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
fi
else
print_error "Unsupported pager '$(get_pager)' for option "\
"-p/--less-search-pattern"
print_error "Unsupported pager '$(pager_name)' for option "\
"-p/--search-pattern"
exit 1
fi
fi