From 9e86ffe3bc88aa153625389df0068223ee021243 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 4 Nov 2021 14:58:18 +0100 Subject: [PATCH] __fish_print_help: Fix unicode characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- share/functions/__fish_print_help.fish | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index bb836dc99..ebd89685c 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -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