Show manpage for command under cursor

This commit lets you check the manpage for a leading command by moving
the cursor over it, matching the behavior of tab complete.

It also lets you select the man page for the base of a two-part command
like `string match`.

The additional regex case is added because
`commandline -t` returns an empty string when the cursor is after a
space, e.g. at the end of 'sudo ', which the later checks don't handle.

This diagram shows the manpage picked for different cursor positions:

    > sudo -Es time git commit -m foo
      +-------++---++--++------------+
      |       ||   ||  ||            |
      |       ||   ||  |+------------+
      |       ||   ||  |  git-commit
      |       ||   |+--+
      |       ||   | git
      |       |+---+
      |       | time
      +-------+
         sudo
This commit is contained in:
Evan Lloyd New-Schmidt 2022-06-16 15:15:49 -04:00 committed by Johannes Altmanninger
parent 42a9dfa08a
commit a605bcb830

View file

@ -1,6 +1,6 @@
function __fish_man_page
# Get all commandline tokens not starting with "-"
set -l args (commandline -po | string match -rv '^-')
# Get all commandline tokens not starting with "-", up to and including the cursor's
set -l args (string match -rv '^-|^$' -- (commandline -cpo && commandline -t))
# If commandline is empty, exit.
if not set -q args[1]