2019-10-06 21:14:10 +08:00
|
|
|
# This function is typically bound to Alt-W, it is used to list man page entries
|
|
|
|
# for the command under the cursor.
|
2020-07-11 19:54:19 +08:00
|
|
|
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)
|
2019-10-06 21:14:10 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
test -n "$token"
|
|
|
|
or return
|
2020-07-11 19:54:19 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
printf "\n"
|
|
|
|
set -l desc "$token: nothing appropriate."
|
2020-07-11 19:54:19 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
set -l tokentype (type --type $token 2>/dev/null)
|
2020-07-11 19:54:19 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
switch "$tokentype"
|
|
|
|
case function
|
|
|
|
set -l funcinfo (functions $token --details --verbose)
|
2020-07-11 19:54:19 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
test $funcinfo[5] != n/a
|
|
|
|
and set desc "$token - $funcinfo[5]"
|
2020-07-12 03:13:47 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
case builtin
|
|
|
|
set desc (__fish_print_help $token | awk "/./ {print; exit}")
|
2019-10-06 21:14:10 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
case file
|
|
|
|
set -l tmpdesc (whatis $token 2>/dev/null)
|
|
|
|
and set desc $tmpdesc
|
|
|
|
end
|
2020-07-12 02:53:25 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
printf "%s\n" $desc
|
2019-10-06 21:14:10 +08:00
|
|
|
|
2020-07-12 03:19:37 +08:00
|
|
|
set -l line_count (count (fish_prompt))
|
|
|
|
# Ensure line_count is greater than one to accomodate different
|
|
|
|
# versions of the `seq` command, some of which print the sequence in
|
|
|
|
# reverse order when the second argument is smaller than the first
|
|
|
|
if test $line_count -gt 1
|
|
|
|
for x in (seq 2 $line_count)
|
|
|
|
printf "\n"
|
|
|
|
end
|
2019-10-06 21:14:10 +08:00
|
|
|
end
|
2020-07-12 03:19:37 +08:00
|
|
|
|
|
|
|
commandline -f repaint
|
2019-10-06 21:14:10 +08:00
|
|
|
end
|