Skip to content

Commit

Permalink
fun/man: act correctly on 'man builtin | editor'
Browse files Browse the repository at this point in the history
When the regular man(1) output is piped into another command, then
man(1) adapts: it disables terminal formatting and sets the column
width to 80. This function should do the same for the built-in
commands so that e.g. 'man iffe | vi' works as expected and does
not show a lot of control codes in the editor.
  • Loading branch information
McDutchie committed Feb 29, 2024
1 parent 04b4868 commit aad4d80
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cmd/ksh93/fun/man
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ namespace man

show_selfdoc()
{
typeset -x ERROR_OPTIONS=emphasis
export LINES COLUMNS
typeset -x COLUMNS=$COLUMNS # export in local scope
if ((stdout_on_terminal)); then
typeset -x ERROR_OPTIONS=emphasis
else
COLUMNS=80
fi
case $1 in
test ) command test '--??man' -- ;;
[ ) command [ '--??man' -- ] ;;
Expand All @@ -105,6 +109,7 @@ namespace man
pager()
{
typeset pager=${MANPAGER:-${PAGER-}}
((!stdout_on_terminal)) && pager=cat
case $pager in
'') pager='less -R' ;;
less | */less | 'less '* | */'less '*)
Expand Down Expand Up @@ -168,6 +173,11 @@ function man
{
typeset IFS # local default split...
set -o noglob # ...and no pathname expansion, for safe field splitting
# set stdout_on_terminal to 1 if standard output is on a terminal;
# this needs flagging now as show_selfdoc() will have stdout on a pipe
[[ -t 1 ]]
typeset -si stdout_on_terminal=$((! $?))
# and off we go
.man.main "$@"
}

Expand Down

0 comments on commit aad4d80

Please sign in to comment.