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

View File

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