This behavior comes from the “alternate screen” feature included in some (hardware) terminals and most (software) terminal emulators. What happens is that some terminal-aware programs switch to the alternate ‘screen’ to do their work and switch back to the normal ‘screen’ when they are dismissed (quit, suspended, etc.). This effectively clears away the final output of such programs.
A web search for “terminfo prevent altscreen” provided a page that discusses the alternate screen ‘problem’ and several solutions.
As that linked page describes, some programs can be configured to avoid using the alternate screen. The -X
option for less is an indirect way of doing this. Vim can be configured similarly by unsetting the t_ti
and t_te
variables.
A solution with a wider scope is to edit the terminfo entry for your terminal so that it does not include the alternate screen control sequences. The terminfo entries form a database that tell programs which control sequences to send to a terminal to create certain effects (moving the cursor, clearing the screen, erasing part of the current line, etc.). By editing the terminfo entry that your terminal uses, you can arrange to ‘neglect to tell’ all terminfo-using programs that the “alternate screen” control sequences even exist.
From the list of the control sequences for xterm, we can see that the control sequences of interest (for xterm-like terminal emulators) are
- enable alternate screen:
ESC [ ? 47 h
(likewise for 1047 and 1049), and
- restore normal screen:
ESC [ ? 47 l
(likewise for 1047 and 1049).
These codes are most likely present in the terminfo variables smcup
and rmcup
. A quick and dirty way to excise these variables for your current TERM might look like this:
infocmp | sed -e 's/[sr]mcup=[^,]*,//' > /tmp/noaltscreen-terminfo
tic -o ~/.terminfo/ /tmp/noaltscreen-terminfo
This method is quite crude and will certainly not work for all terminals, but it will probably work for most xterm-like terminal emulators. Ideally you should investigate the values in the smcup
and rmcup
variables of the terminfo entry for your terminal and conservatively edit them to prevent the undesired behavior. The above-linked discussion/solution page has a “pre-cooked” terminfo file that you might use instead of hacking your own (but what is the fun in that?).
You can evaluate comments before the slash, simply generating empty strings for comments which won't affect your script:
bwa aln \
-n $n `# -n max #diff (integer) or missing prob under 0.02 err rate (float) [0.04]` \
-o $o `# -o maximum number or fraction of gap opens [1]` \
....
Best Answer
Perhaps you like to have some wrapper function which skips directly to the builtin:
-P
tells man to use less as pager (probably the default on most systems), but pass directly a search to it. You need to add some blanks before the search string to skip hits in text and go to the description of the command.For convenience make a function out of it and put it into your
~/.bashrc
:and use it like
manbash pushd
.Another possibility is to use the bash builtin
help
: