Use mandoc when nroff not available

mandoc users do not need to install nroff to be able to format and view
manual pages. If both nroff and mandoc cannot be found it will show an
error.
This commit is contained in:
John McKay 2019-01-06 04:00:03 +00:00 committed by Fabian Homborg
parent 1f897d2c43
commit 827bce6c88
2 changed files with 26 additions and 11 deletions

View file

@ -13,6 +13,7 @@
- nothing yet... - nothing yet...
- Lots of improvements to completions. - Lots of improvements to completions.
- fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard). - fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard).
- mandoc can now be used to format the output from `--help` if nroff is not installed
--- ---

View file

@ -10,21 +10,35 @@ function __fish_print_help --description "Print help message for the specified f
# Render help output, save output into the variable 'help' # Render help output, save output into the variable 'help'
set -l help set -l help
set -l cols $COLUMNS set -l format
set -l rLL set -l cols
if test -n "$COLUMNS"
set cols (math $COLUMNS - 4) # leave a bit of space on the right
end
# Pick which command we are using to render output or fail if none
if command -qs nroff
set format nroff -c -man -t
if test -e $__fish_data_dir/groff/fish.tmac
set -a format -M$__fish_data_dir/groff -mfish
end
if test -n "$cols" if test -n "$cols"
set cols (math $cols - 4) # leave a bit of space on the right set -a format -rLL={$cols}n
set rLL -rLL=$cols[1]n
end end
set -lx GROFF_TMAC_PATH $__fish_data_dir/groff else if command -qs mandoc
set -l mfish set format mandoc -c
if test -e $GROFF_TMAC_PATH/fish.tmac if test -n "$cols"
set mfish -mfish set -a format -O width=$cols
end end
else
echo fish: (_ "Cannot format help; no parser found")
return 1
end
if test -e "$__fish_data_dir/man/man1/$item.1" if test -e "$__fish_data_dir/man/man1/$item.1"
set help (nroff -c -man $mfish -t $rLL "$__fish_data_dir/man/man1/$item.1" 2>/dev/null) set help ($format "$__fish_data_dir/man/man1/$item.1" 2>/dev/null)
else if test -e "$__fish_data_dir/man/man1/$item.1.gz" else if test -e "$__fish_data_dir/man/man1/$item.1.gz"
set help (gunzip -c "$__fish_data_dir/man/man1/$item.1.gz" 2>/dev/null | nroff -c -man $mfish -t $rLL 2>/dev/null) set help (gunzip -c "$__fish_data_dir/man/man1/$item.1.gz" 2>/dev/null | $format 2>/dev/null)
end end
# The original implementation trimmed off the top 5 lines and bottom 3 lines # The original implementation trimmed off the top 5 lines and bottom 3 lines