mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Add support for subcommands in __fish_man_page
This commit adds a feature that after typing "git add" and pressing "alt+h", the manpage for "git-add" instead of "git" would be displayed. The new logic takes the first argument which doesn't start with a dash and tries to display manpage for "command-argument"; it falls back to "man command" it the first try doesn't succeed. Fixes #3618.
This commit is contained in:
parent
52c7ebe502
commit
f9835b5077
1 changed files with 22 additions and 2 deletions
|
@ -1,4 +1,24 @@
|
||||||
function __fish_man_page
|
function __fish_man_page
|
||||||
man (basename (commandline -po; echo)[1]) ^/dev/null
|
# Get all commandline tokens not starting with "-"
|
||||||
or printf \a
|
set -l args (commandline -po | string match -rv '^-')
|
||||||
|
|
||||||
|
# If commandline is empty, exit.
|
||||||
|
if not set -q args[1]
|
||||||
|
printf \a
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
man "$maincmd-$args[2]" ^/dev/null
|
||||||
|
or man "$maincmd" ^/dev/null
|
||||||
|
or printf \a
|
||||||
|
else
|
||||||
|
man "$maincmd" ^/dev/null
|
||||||
|
or printf \a
|
||||||
|
end
|
||||||
|
|
||||||
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue