2019-09-08 00:19:12 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# bat-extras | Copyright (C) 2019 eth-p | MIT License
|
|
|
|
#
|
|
|
|
# Repository: https://github.com/eth-p/bat-extras
|
|
|
|
# Issues: https://github.com/eth-p/bat-extras/issues
|
|
|
|
# -----------------------------------------------------------------------------
|
2020-01-21 23:09:43 +01:00
|
|
|
LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")/../lib" && pwd)"
|
2019-09-09 02:43:29 +02:00
|
|
|
BAT="bat"
|
2020-02-16 00:10:18 +01:00
|
|
|
if [[ -n "${MANPAGER}" ]]; then BAT_PAGER="$MANPAGER"; fi
|
2019-12-24 01:35:28 +01:00
|
|
|
source "${LIB}/pager.sh"
|
2019-09-08 00:19:12 +02:00
|
|
|
source "${LIB}/print.sh"
|
|
|
|
source "${LIB}/opt.sh"
|
2019-10-23 00:35:10 +02:00
|
|
|
source "${LIB}/opt_hooks.sh"
|
2019-09-08 00:19:12 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
2019-10-23 00:35:10 +02:00
|
|
|
hook_color
|
2019-12-24 01:35:28 +01:00
|
|
|
hook_pager
|
2019-10-23 00:35:10 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
MAN_ARGS=()
|
|
|
|
BAT_ARGS=()
|
2019-09-08 00:19:12 +02:00
|
|
|
|
2019-10-23 00:35:10 +02:00
|
|
|
while shiftopt; do MAN_ARGS+=("$OPT"); done
|
|
|
|
if "$OPT_COLOR"; then
|
|
|
|
BAT_ARGS="--color=always --decorations=always"
|
|
|
|
else
|
|
|
|
BAT_ARGS="--color=never --decorations=never"
|
|
|
|
fi
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
export MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language=man --style=grid '"${BAT_ARGS[@]}"'"'
|
2019-09-08 00:19:12 +02:00
|
|
|
export MANROFFOPT='-c'
|
|
|
|
|
2019-12-24 01:35:28 +01:00
|
|
|
if [[ -n "${SCRIPT_PAGER_CMD}" ]]; then
|
2019-12-24 02:08:32 +01:00
|
|
|
export BAT_PAGER="$(printf "%q " "${SCRIPT_PAGER_CMD[@]}" "${SCRIPT_PAGER_ARGS[@]}")"
|
2019-12-24 01:35:28 +01:00
|
|
|
else
|
|
|
|
unset BAT_PAGER
|
|
|
|
fi
|
|
|
|
|
2019-10-23 00:35:10 +02:00
|
|
|
command man "${MAN_ARGS[@]}"
|
2019-09-08 00:19:12 +02:00
|
|
|
exit $?
|