From d9e34e2d5fdd7a8725b029bac513caa062377c6e Mon Sep 17 00:00:00 2001 From: Ethan P Date: Tue, 22 Oct 2019 15:35:10 -0700 Subject: [PATCH] Add color option to batman --- src/batman.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/batman.sh b/src/batman.sh index b795b49..8057d6c 100755 --- a/src/batman.sh +++ b/src/batman.sh @@ -9,13 +9,24 @@ LIB="$(cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}" BAT="bat" source "${LIB}/print.sh" source "${LIB}/opt.sh" -source "${LIB}/version.sh" +source "${LIB}/opt_hooks.sh" # ----------------------------------------------------------------------------- +hook_color +# ----------------------------------------------------------------------------- +MAN_ARGS=() +BAT_ARGS=() -export MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language man --style grid"' +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[@]}"'"' export MANROFFOPT='-c' export BAT_PAGER="$PAGER" -command man "$@" +command man "${MAN_ARGS[@]}" exit $?