fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Gleb Smirnovfix: treat `run0` and `please` as a prefix in `__fish_man_page`3518d4f6a

master
1.5 KiB39 linesraw
1# localization: skip(private)
2function __fish_man_page
3    # Get all commandline tokens not starting with "-", up to and including the cursor's
4    set -l args (string match -rv '^-|^$' -- (commandline -cpx && commandline -t))
5
6    # If commandline is empty, exit.
7    if not set -q args[1]
8        printf \a
9        return
10    end
11
12    # Skip leading commands and display the manpage of following command
13    while set -q args[2]
14        and 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]
15        set -e args[1]
16    end
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.
20    set -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.
26    if set -q args[2]
27        and not string match -q -- '*/*' $args[2]
28        and man "$maincmd-$args[2]" &>/dev/null
29        man "$maincmd-$args[2]"
30    else
31        if man "$maincmd" &>/dev/null
32            man "$maincmd"
33        else
34            printf \a
35        end
36    end
37
38    commandline -f repaint
39end