From d0ce5fe94343dee02d23d1f9fbacc1da518a73cf Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 11 Jul 2020 17:24:19 +0530 Subject: [PATCH] Show function description if available with whatis_current_token By default __fish_whatis_current_token is bound to ALt-W --- .../__fish_whatis_current_token.fish | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/share/functions/__fish_whatis_current_token.fish b/share/functions/__fish_whatis_current_token.fish index e5269e68f..faa678e7e 100644 --- a/share/functions/__fish_whatis_current_token.fish +++ b/share/functions/__fish_whatis_current_token.fish @@ -1,11 +1,25 @@ # This function is typically bound to Alt-W, it is used to list man page entries # for the command under the cursor. -function __fish_whatis_current_token -d "Show man page entries related to the token under the cursor" - set -l tok (commandline -pt) +function __fish_whatis_current_token -d "Show man page entries or function description related to the token under the cursor" + set -l token (commandline -pt) - if test -n "$tok[1]" + if test -n "$token" printf "\n" - whatis $tok[1] + whatis $token 2>/dev/null + + if test $status -eq 16 # no match found + set -l tokentype (type --type $token 2>/dev/null) + set -l desc ": nothing appropriate." + + if test "$tokentype" = "function" + set -l funcinfo (functions $token --details --verbose) + + test $funcinfo[5] != "n/a" + and set desc " - $funcinfo[5]" + end + + printf "%s%s\n" $token $desc + end set -l line_count (count (fish_prompt)) # Ensure line_count is greater than one to accomodate different