#!/bin/sh

# Force using the ~/bin/less wrapper for LESS_TERMCAP overrides.
if [ ! "$PAGER" ] && [ ! "$MANPAGER" ]; then
	export PAGER="less"
fi

# Disable "new" rendering mode in grotty(1) so that the LESS_TERMCAP overrides
# would work. (Note: Debian already disables this by default and adds GROFF_SGR
# to un-do that, so let's honor that here as well.)
if [ ! "$GROFF_SGR" ]; then
	export GROFF_NO_SGR=1
fi

# Initialize to (approximately) the default 'man -r' value
export MANLESS="?ltline %lt?L/%L.:byte %bB?s/%s..?pB (%pB\\%). "

# Set terminal title to "manpage(section)".
#case $TERM in
#    xterm*)
#	export MANLESS="${MANLESS}$(printf '\e]0;$MAN_PN\a')";;
#    tmux*)
#	export MANLESS="${MANLESS}$(printf '\ek$MAN_PN\e\\\\')";;
#    *)
#	export MANLESS="\$MAN_PN ${MANLESS}";;
#esac
# Unfortunately, less v591 broke the use of \e in prompt strings -- so it works
# on Fujitsu but not on any of my other machines -- therefore disable it for now.
export MANLESS="\$MAN_PN ${MANLESS}"

exec /usr/bin/man "$@"
