less
less copied to clipboard
Support for the terminal title as part of the prompt string
Up to less v590, I used to (ab)use $MANLESS – which the man tool injects into $LESS as the -P option, for customizing the prompt – to additionally set the terminal title to the name of the manual page being shown. (This was a convenient way to do it because man automatically fills in the actual name(section) it's currently showing, which isn't known upfront so doing it from a shell alias would be troublesome.).
It wasn't a very good method (as it caused less to think that the prompt was twice as long as it was, leading to it getting prematurely truncated), but it worked well enough.
Basically I had an \e]0;$MAN_PN\a (ESC ] 0 ... BEL) as part of $MANLESS:
# approximately the default value of 'man -r'
export MANLESS="?ltline %lt?L/%L.:byte %bB?s/%s..?pB (%pB\\%). "
# put "manpage(section)" in the terminal title for xterm, in the less prompt otherwise
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
This stopped working in less v591, which enabled ANSI formatting in the prompt, but as a consequence the whole ESC ]0; now gets thrown away and the rest remains visible in the prompt.