fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a1baf97f5
master
1# localization: skip(private) 2function __fish_complete_man 3# Try to guess what section to search in. If we don't know, we 4# use [^)]*, which should match any section. 5set -l section"" 6set -l token( commandline -ct) 7set -l prev( commandline -pxc) 8set -e prev[ 1 ] 9while set -q prev[ 1 ] 10switch $prev [ 1 ] 11case '-**' 12 13case '*' 14set section( string escape --style=regex$prev [ 1 ]) 15set section( string replace --all /\\ /$section ) 16end 17set -e prev[ 1 ] 18end 19 20set -l exclude_fish_commands 21# Only include fish commands when section is empty or 1 22if test -z " $section " -o " $section " = 1 23set -e exclude_fish_commands 24end 25 26set section$section "[^)]*" 27# If we don't have a token but a section, list all pages for that section. 28# Don't do it for all sections because that would be overwhelming. 29if test -z " $token " -a " $section " != "[^)]*" 30set token"." 31end 32 33if test -n " $token " 34# Do the actual search 35__fish_apropos ^$token 2> /dev/null| awk ' 36BEGIN { FS="[\t ]- "; OFS="\t"; } 37# BSD/Darwin 38/^[^( \t]+(, [^( \t]+)*\(' $section '\)/ { 39paren = index($1, "("); 40sect = substr($1, paren + 1, length($1) - paren - 1); 41aliases = substr($1, 1, paren - 1) 42split(aliases, pages, ", "); 43for (i in pages) { 44print pages[i], sect ": " $2 45} 46} 47# man-db 48/^[^( \t]+ +\(' $section '\)/ { 49split($1, t, " "); 50sect = substr(t[2], 2, length(t[2]) - 2); 51print t[1], sect ": " $2; 52} 53# man-db RHEL 5 with [aliases] 54/^[^( \t]+ +\[.*\] +\(' $section '\)/ { 55split($1, t, " "); 56sect = substr(t[3], 2, length(t[3]) - 2); 57print t[1], sect ": " $2; 58} 59# Solaris 11 60# Does not display descriptions 61# Solaris apropos outputs embedded backspace in descriptions 62/^[0-9]+\. [^( \t]*\(' $section '\) / { 63split($1, t, " ") 64paren = index(t[2], "("); 65name = substr(t[2], 1, paren - 1); 66sect = substr(t[2], paren + 1, length(t[2]) - paren - 1); 67print name, sect 68} 69' 70 71# Fish commands are not given by apropos 72if not set -ql exclude_fish_commands 73string join\n --( __fish_man1_pages ) \t'1: fish command' 74end 75else 76return 1 77end 78return 0 79end