__fish_print_help: Fix unicode characters

This is nroff/groff being broken. It turns "→" into "â". This is even if we select `-Tutf8` and friends.

So, if mandoc exists, we prefer that, and otherwise, run preconv on
the file first (if it exists).

Really, what we would need to to is tell nroff to pass `-KUTF-8` to
groff, but that doesn't appear to be possible.
This commit is contained in:
Fabian Homborg 2021-11-04 14:58:18 +01:00
parent 45de6d167d
commit 9e86ffe3bc

View file

@ -22,7 +22,13 @@ function __fish_print_help --description "Print help message for the specified f
end
# Pick which command we are using to render output or fail if none
if command -qs nroff
# We prefer mandoc because that doesn't break with unicode input.
if command -qs mandoc
set format mandoc -c
if test -n "$cols"
set -a format -O width=$cols
end
else 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
@ -30,20 +36,26 @@ function __fish_print_help --description "Print help message for the specified f
if test -n "$cols"
set -a format -rLL={$cols}n
end
else if command -qs mandoc
set format mandoc -c
if test -n "$cols"
set -a format -O width=$cols
end
else
echo fish: (_ "Cannot format help; no parser found")
return 1
end
if test -e "$__fish_data_dir/man/man1/$item.1"
set help ($format "$__fish_data_dir/man/man1/$item.1" 2>/dev/null)
# Some nroff versions screw up non-ascii characters.
# (even with the locale set correctly!)
# Work around that by running preconv first.
if command -sq preconv; and test "$format[1]" = nroff
set help (preconv -e UTF-8 "$__fish_data_dir/man/man1/$item.1" | $format 2>/dev/null)
else
set help ($format "$__fish_data_dir/man/man1/$item.1" 2>/dev/null)
end
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 | $format 2>/dev/null)
if command -sq preconv; and test "$format[1]" = nroff
set help (gunzip -c "$__fish_data_dir/man/man1/$item.1.gz" 2>/dev/null | preconv -e UTF-8 | $format 2>/dev/null)
else
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