From ebde55f7047aa56ce69bf33ce8fb62c7e9f2a37d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 29 May 2016 14:31:12 +0200 Subject: Man completions: Show all pages for a section If one is given, of course. --- share/functions/__fish_complete_man.fish | 35 ++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'share') diff --git a/share/functions/__fish_complete_man.fish b/share/functions/__fish_complete_man.fish index 1bdaa5c6..7306dd2c 100644 --- a/share/functions/__fish_complete_man.fish +++ b/share/functions/__fish_complete_man.fish @@ -1,27 +1,33 @@ function __fish_complete_man - if test (commandline -ct) + # Try to guess what section to search in. If we don't know, we + # use [^)]*, which should match any section - # Try to guess what section to search in. If we don't know, we - # use [^)]*, which should match any section - - set section "" - set prev (commandline -poc) - set -e prev[1] - while count $prev - switch $prev[1] + set section "" + set prev (commandline -poc) + set -e prev[1] + while count $prev + switch $prev[1] case '-**' case '*' set section $prev[1] - end - set -e prev[1] end + set -e prev[1] + end + + set section $section"[^)]*" - set section $section"[^)]*" + set -l token (commandline -ct) + # If we don't have a token but a section, list all pages for that section. + # Don't do it for all sections because that would be overwhelming. + if test -z "$token" -a "$section" != "[^)]*" + set token "." + end + if test -n "$token" # Do the actual search - apropos (commandline -ct) ^/dev/null | awk ' + apropos $token ^/dev/null | awk ' BEGIN { FS="[\t ]- "; OFS="\t"; } # BSD/Darwin /^[^( \t]+\('$section'\)/ { @@ -58,6 +64,9 @@ function __fish_complete_man print name, sect } ' + else + return 1 end + return 0 end -- cgit v1.2.3