2014-09-28 17:09:14 +08:00
|
|
|
function __fish_man_page
|
2016-12-26 21:27:38 +08: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-19 04:35:33 +08:00
|
|
|
#Skip `sudo` and display then manpage of following command
|
|
|
|
while set -q args[2]
|
|
|
|
and test $args[1] = "sudo"
|
|
|
|
set args $args[2..-1]
|
|
|
|
end
|
|
|
|
|
2016-12-26 21:27:38 +08: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]
|
2018-04-02 04:42:38 +08:00
|
|
|
man "$maincmd-$args[2]" 2>/dev/null
|
|
|
|
or man "$maincmd" 2>/dev/null
|
2016-12-26 21:27:38 +08:00
|
|
|
or printf \a
|
|
|
|
else
|
2018-04-02 04:42:38 +08:00
|
|
|
man "$maincmd" 2>/dev/null
|
2016-12-26 21:27:38 +08:00
|
|
|
or printf \a
|
|
|
|
end
|
|
|
|
|
|
|
|
commandline -f repaint
|
2014-09-28 17:09:14 +08:00
|
|
|
end
|