__fish_print_help: use man as-is

Since 0fea1dae8c (__fish_print_help: Make formatting more man-like,
2024-10-03), there is barely any difference left between "man abbr"
and "abbr -h".

The main difference is that it looks almost like man but is actually
nroff/mandoc and less.  This means it doesn't support environment
variables like MANWIDTH and possibly others.

Let's use full "man" for now.
This matches what "git foo --help" does so it's widely accepted.

Keep around a fallback for a while, in case users/packagers fail to
install the new "man" dependency.

In future, "abbr -h" (as opposed to "abbr --help") could show a more
concise version, not sure.

Closes #11786
This commit is contained in:
Johannes Altmanninger
2025-08-29 10:39:15 +02:00
parent d422ad603e
commit 5ece9bec6c
13 changed files with 66 additions and 8 deletions

View File

@@ -58,6 +58,7 @@ Interactive improvements
- Pasted commands are now stripped of any :code:`$\ ` command prefixes, which are sometimes used in copy-pasted code snippets.
- The :kbd:`alt-s` binding will now also use ``run0`` if available.
- ``funced`` will now edit copied functions directly, instead of the file where ``function --copy`` was invoked. (:issue:`11614`)
- built-in help options as ``abbr --help`` now use ``man`` directly, meaning that variables like :envvar:`MANWIDTH` are respected (:issue:`11786`).
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,6 +96,8 @@ For distributors
it will act like the given tool (i.e. it's a multi-call binary).
This allows truly distributing fish as a single file.
This means they can be replaced with symlinks if you want to save disk space (:issue:`10876`).
- builtin commands that support the ``--help`` option now require the ``man`` program.
The direct dependency on either of ``mandoc`` or ``nroff`` has been removed.
- The CMake build configuration has been simplified and no longer second-guesses rustup.
It will run rustc and cargo via :envvar:`PATH` or in ~/.cargo/bin/.
If that doesn't match your setup, set the Rust_COMPILER and Rust_CARGO cmake variables (:issue:`11328`).

View File

@@ -97,8 +97,7 @@ Running fish requires:
The following optional features also have specific requirements:
- builtin commands that have the ``--help`` option or print usage
messages require ``nroff`` or ``mandoc`` for
display
messages require ``man`` for display
- automated completion generation from manual pages requires Python 3.5+
- the ``fish_config`` web configuration tool requires Python 3.5+ and a web browser
- system clipboard integration (with the default Ctrl-V and Ctrl-X

4
debian/control vendored
View File

@@ -25,8 +25,8 @@ Depends: bsdextrautils | bsdmainutils,
file,
# for the msgfmt command
gettext-base,
# for nroff and preconv
groff-base,
# for man
man-db,
# for terminal definitions
ncurses-base,
# for kill

View File

@@ -43537,6 +43537,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43533,6 +43533,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43634,6 +43634,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43529,6 +43529,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43550,6 +43550,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43532,6 +43532,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr ""

View File

@@ -43532,6 +43532,9 @@ msgstr ""
msgid "Print help for the given subcommand(s)"
msgstr ""
msgid "Print help for the specified fish function or builtin"
msgstr ""
msgid "Print help info and exit"
msgstr "打印帮助信息和退出"

View File

@@ -1,4 +1,4 @@
function __fish_print_help --description "Print help message for the specified fish function or builtin"
function __fish_print_help --description "Print help for the specified fish function or builtin"
set -l item $argv[1]
switch $item
case !
@@ -11,8 +11,41 @@ function __fish_print_help --description "Print help message for the specified f
set item test
end
if not command -v man >/dev/null
__fish_print_help_pre_4.1 \
$item \
"fish: warning: Unknown command 'man', falling back to 'mandoc' or 'nroff'"
return
end
# NOTE: this is duplicated with share/functions/man.fish, but that
# function is not always defined.
set -l tmpdir
set -l file (path filter -- \
$__fish_data_dir/man/man1/$item.1 \
$__fish_data_dir/man/man1/$item.1.gz)
or begin
set -l contents "$(status get-file man/man1/$item.1)"
or return 2
set tmpdir (__fish_mktemp_relative -d fish-print-help)
or return
set file $tmpdir/$item.1
printf %s\n $contents >$file
end
command man $file[1]
set -l saved_status $status
if set -q tmpdir[1]
command rm -r $tmpdir
end
return $saved_status
end
function __fish_print_help_pre_4.1 --description "Print help message for the specified fish function or builtin"
set -l item $argv[1]
set -l error_message $argv[2]
# Do nothing if the file does not exist
if not path is -- $__fish_data_dir/man/man1/$item.1 $__fish_data_dir/man/man1/$item.1.gz; and not status get-file man/man1/$item.1 >/dev/null
if not path is -- $__fish_data_dir/man/man1/$item.1 $__fish_data_dir/man/man1/$item.1.gz
and not status get-file man/man1/$item.1 >/dev/null
return 2
end
@@ -76,6 +109,7 @@ function __fish_print_help --description "Print help message for the specified f
set -l state blank
set -l have_name
begin
string join \n $error_message
for line in $help
# categorize the line
set -l line_type

View File

@@ -18,7 +18,8 @@ function __fish_whatis_current_token -d "Show man page entries or function descr
and set desc "$token - $funcinfo[5]"
case builtin
set desc (__fish_print_help $token | awk "/./ { getline; print; exit }" | string trim)
# Since man pages can be localized, we can't look for "NAME".
set desc (__fish_print_help $token | sed -n 4p | string trim)
case file
set -l tmpdesc (whatis $token 2>/dev/null)

View File

@@ -1,6 +1,6 @@
# RUN: %fish %s
# Test redirecting builtin help with a pipe
# REQUIRES: command -v mandoc || command -v nroff
# REQUIRES: command -v man
set -lx __fish_data_dir (mktemp -d)
mkdir -p $__fish_data_dir/man/man1