fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
3518d4f6a
master
1# localization: skip(private) 2function __fish_man_page 3# Get all commandline tokens not starting with "-", up to and including the cursor's 4set -l args( string match -rv'^-|^$' --( commandline -cpx&& commandline -t)) 5 6# If commandline is empty, exit. 7if not set -q args[ 1 ] 8printf \a 9return 10end 11 12# Skip leading commands and display the manpage of following command 13while set -q args[ 2 ] 14and string match -qr --'^(and|begin|builtin|caffeinate|command|doas|entr|env|exec|if|mosh|nice|not|or|pipenv|please|prime-run|run0|setsid|sudo|systemd-nspawn|time|watch|while|xargs|.*=.*)$' $args [ 1 ] 15set -e args[ 1 ] 16end 17 18# If there are at least two tokens not starting with "-", the second one might be a subcommand. 19# Try "man first-second" and fall back to "man first" if that doesn't work out. 20set -l maincmd( path basename$args [ 1 ]) 21# HACK: If stderr is not attached to a terminal `less` (the default pager) 22# wouldn't use the alternate screen. 23# But since we don't know what pager it is, and because `man` is totally underspecified, 24# the best we can do is to *try* the man page, and assume that `man` will return false if it fails. 25# See #7863. 26if set -q args[ 2 ] 27and not string match -q --'*/*' $args [ 2 ] 28and man " $maincmd - $args [ 2 ] " &> /dev/null 29man " $maincmd - $args [ 2 ] " 30else 31if man " $maincmd " &> /dev/null 32man " $maincmd " 33else 34printf \a 35end 36end 37 38commandline -f repaint 39end