__fish_man_page: simplify

This helps the next commit. No functional change.
This commit is contained in:
Johannes Altmanninger 2022-05-13 20:39:20 +02:00
parent 72ae46e922
commit bb325e497a

View file

@ -8,7 +8,7 @@ function __fish_man_page
return return
end end
# Skip leading commands and display then manpage of following command # Skip leading commands and display the manpage of following command
while set -q args[2] while set -q args[2]
and string match -qr -- '^(and|begin|builtin|caffeinate|command|doas|entr|env|exec|if|mosh|nice|not|or|pipenv|prime-run|setsid|sudo|systemd-nspawn|time|watch|while|xargs|.*=.*)$' $args[1] and string match -qr -- '^(and|begin|builtin|caffeinate|command|doas|entr|env|exec|if|mosh|nice|not|or|pipenv|prime-run|setsid|sudo|systemd-nspawn|time|watch|while|xargs|.*=.*)$' $args[1]
set -e args[1] set -e args[1]
@ -17,19 +17,14 @@ function __fish_man_page
# If there are at least two tokens not starting with "-", the second one might be a subcommand. # If there are at least two tokens not starting with "-", the second one might be a subcommand.
# Try "man first-second" and fall back to "man first" if that doesn't work out. # Try "man first-second" and fall back to "man first" if that doesn't work out.
set -l maincmd (basename $args[1]) set -l maincmd (basename $args[1])
# HACK: If stderr is not attached to a terminal `less` (the default pager)
# wouldn't use the alternate screen.
# But since we don't know what pager it is, and because `man` is totally underspecified,
# the best we can do is to *try* the man page, and assume that `man` will return false if it fails.
# See #7863.
if set -q args[2] if set -q args[2]
# HACK: If stderr is not attached to a terminal `less` (the default pager) and man "$maincmd-$args[2]" &>/dev/null
# wouldn't use the alternate screen. man "$maincmd-$args[2]"
# But since we don't know what pager it is, and because `man` is totally underspecified,
# the best we can do is to *try* the man page, and assume that `man` will return false if it fails.
# See #7863.
if man "$maincmd-$args[2]" &>/dev/null
man "$maincmd-$args[2]"
else if man "$maincmd" &>/dev/null
man "$maincmd"
else
printf \a
end
else else
if man "$maincmd" &>/dev/null if man "$maincmd" &>/dev/null
man "$maincmd" man "$maincmd"