2014-09-28 09:09:14 +00:00
|
|
|
function __fish_man_page
|
2016-12-26 13:27:38 +00:00
|
|
|
# Get all commandline tokens not starting with "-"
|
|
|
|
set -l args (commandline -po | string match -rv '^-')
|
|
|
|
|
|
|
|
# If commandline is empty, exit.
|
|
|
|
if not set -q args[1]
|
|
|
|
printf \a
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-09-18 20:35:33 +00:00
|
|
|
#Skip `sudo` and display then manpage of following command
|
2019-11-16 13:57:59 +00:00
|
|
|
while set -q args[2]
|
2019-12-19 22:41:26 +00:00
|
|
|
and string match -qr -- '^(sudo|.*=.*)$' $args[1]
|
|
|
|
set -e args[1]
|
2019-09-18 20:35:33 +00:00
|
|
|
end
|
|
|
|
|
2016-12-26 13:27:38 +00:00
|
|
|
# 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.
|
|
|
|
set -l maincmd (basename $args[1])
|
|
|
|
if set -q args[2]
|
2021-03-27 08:14:49 +00:00
|
|
|
# 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 man "$maincmd-$args[2]" &>/dev/null
|
|
|
|
man "$maincmd-$args[2]"
|
|
|
|
else if man "$maincmd" &>/dev/null
|
|
|
|
man "$maincmd"
|
|
|
|
else
|
|
|
|
printf \a
|
|
|
|
end
|
2016-12-26 13:27:38 +00:00
|
|
|
else
|
2021-03-27 08:14:49 +00:00
|
|
|
if man "$maincmd" &>/dev/null
|
|
|
|
man "$maincmd"
|
|
|
|
else
|
|
|
|
printf \a
|
|
|
|
end
|
2016-12-26 13:27:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
commandline -f repaint
|
2014-09-28 09:09:14 +00:00
|
|
|
end
|