fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerDo not embed man pages in CMake buildsa1baf97f5

master
2.7 KiB79 linesraw
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.
5    set -l section ""
6    set -l token (commandline -ct)
7    set -l prev (commandline -pxc)
8    set -e prev[1]
9    while set -q prev[1]
10        switch $prev[1]
11            case '-**'
12
13            case '*'
14                set section (string escape --style=regex $prev[1])
15                set section (string replace --all / \\/ $section)
16        end
17        set -e prev[1]
18    end
19
20    set -l exclude_fish_commands
21    # Only include fish commands when section is empty or 1
22    if test -z "$section" -o "$section" = 1
23        set -e exclude_fish_commands
24    end
25
26    set 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.
29    if test -z "$token" -a "$section" != "[^)]*"
30        set token "."
31    end
32
33    if test -n "$token"
34        # Do the actual search
35        __fish_apropos ^$token 2>/dev/null | awk '
36                BEGIN { FS="[\t ]- "; OFS="\t"; }
37                # BSD/Darwin
38                /^[^( \t]+(, [^( \t]+)*\('$section'\)/ {
39                  paren = index($1, "(");
40                  sect = substr($1, paren + 1, length($1) - paren - 1);
41                  aliases = substr($1, 1, paren - 1)
42                  split(aliases, pages, ", ");
43                  for (i in pages) {
44                    print pages[i], sect ": " $2
45                  }
46                }
47                # man-db
48                /^[^( \t]+ +\('$section'\)/ {
49                  split($1, t, " ");
50                  sect = substr(t[2], 2, length(t[2]) - 2);
51                  print t[1], sect ": " $2;
52                }
53                # man-db RHEL 5 with [aliases]
54                /^[^( \t]+ +\[.*\] +\('$section'\)/ {
55                  split($1, t, " ");
56                  sect = substr(t[3], 2, length(t[3]) - 2);
57                  print 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'\) / {
63                  split($1, t, " ")
64                  paren = index(t[2], "(");
65                  name = substr(t[2], 1, paren - 1);
66                  sect = substr(t[2], paren + 1, length(t[2]) - paren - 1);
67                  print name, sect
68                }
69                '
70
71        # Fish commands are not given by apropos
72        if not set -ql exclude_fish_commands
73            string join \n -- (__fish_man1_pages)\t'1: fish command'
74        end
75    else
76        return 1
77    end
78    return 0
79end