From a605bcb830320158b55bd97e62d0018d06095f27 Mon Sep 17 00:00:00 2001 From: Evan Lloyd New-Schmidt Date: Thu, 16 Jun 2022 15:15:49 -0400 Subject: [PATCH] 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 --- share/functions/__fish_man_page.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_man_page.fish b/share/functions/__fish_man_page.fish index ef2bee562..5c8e17ec7 100644 --- a/share/functions/__fish_man_page.fish +++ b/share/functions/__fish_man_page.fish @@ -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]