fork/fish-shell

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

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
4.5 KiB93 linesraw
1function __fish_parse_configure
2    if test (count $argv) -ne 1
3        echo "Usage: parse_configure path/to/configure" 1>&2
4        return 1
5    end
6
7    # `complete` parses `./configure` as `configure` so we have to handle all paths, not just ./
8    if not test -x $argv[1]
9        printf "Cannot find or execute '%s'\n" $argv[1] 1>&2
10        return 1
11    end
12
13    # Must support output along the lines of
14    #  -h, --help              display this help and exit
15    #      --help=short        display options specific to this package
16    #      --help=recursive    display the short help of all the included packages
17    #  -V, --version           display version information and exit
18    #  -q, --quiet, --silent   do not print `checking ...' messages
19
20    set -l next_line
21    set -l line
22    set -l buffer
23    # Just fish's `./configure --help` takes ~350ms to run, before parsing
24    # The following chain attempts to extract the help message:
25    cat $argv[1] | tr \n \u0e | sed -n 's/.*Report the --help message\(.*\?\)ac_status.*/\1/; s/ac_status.*//p' | tr \u0e \n |
26        while test -n "$next_line" || read -lL next_line
27            # In autoconfigure scripts, the first column wraps at 26 chars
28            # echo next_line: $next_line
29            # echo old_line: $line
30            if test -z "$line"
31                set line $next_line
32                set next_line "" # mark it as consumed
33                continue
34            else if string match -qr '^(   |\t){2,}[^-]\S*' -- $next_line
35                # echo "continuation line found. Old value of line: " \"$line\"
36                set line "$line "(string trim $next_line)
37                set next_line "" # mark it as consumed
38                continue
39            end
40
41            # echo line: $line
42
43            # Search for one or more strings starting with `-` separated by commas
44            if string replace -fr '^\s+(-.*?)\s+([^\s\-].*)' '$1\n$2' -- $line | read -lL opts description
45                for opt in (string split -n , -- $opts | string trim)
46
47                    if string match -qr -- '--[a-z_0-9-]+=\[.*\]' $opt
48                        # --option=[OPTIONAL_VALUE]
49                        string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
50                    else if string match -qr -- '--[a-z_0-9-]+\[=.*\]' $opt
51                        # --option[=OPTIONAL_VALUE]
52                        string replace -r -- '(--[a-z_0-9-]+)\[=.*' '$1' $opt | read opt
53                    else if string match -qr -- '--[a-z_0-9-]+=[A-Z]+' $opt
54                        # --option=CLASS_OF_VALUE (eg FILE or DIR)
55                        string replace -r -- '(--[a-z_0-9-]+)=.*' '$1' $opt | read opt
56                    else if string match -qr -- '--[a-z_0-9-]+=\S+' $opt
57                        # --option=literal_value, leave as-is
58                    else if string match -qr -- '--[a-z_0-9-]+$' $opt
59                        # long option, leave as-is
60                    else if string match -qr -- '-[^-]$' $opt
61                        # short option, leave as-is
62                    else
63                        continue
64                    end
65
66                    echo "$opt"\t"$description" # parsed by `complete` as value and description
67                end
68            end
69
70            set line ""
71        end
72end
73
74complete -c configure -s h -l help -x -a "short recursive" -d "Display help and exit"
75complete -c configure -s V -l version -d "Display version and exit"
76complete -c configure -s q -l quiet -d "Quiet mode"
77complete -c configure -l cache-file -f -d "Cache test results in specified file"
78complete -c configure -s C -l config-cache -d "Cache test results in file config.cache"
79complete -c configure -s n -l no-create -d "Do not create output files"
80complete -c configure -l srcdir -d "Set source directory" -a "(__fish_complete_directories)" -x
81complete -c configure -l prefix -d "Architecture-independent install directory" -a "(__fish_complete_directories)" -x
82complete -c configure -l exec-prefix -d "Architecture-dependent install directory" -a "(__fish_complete_directories)" -x
83complete -c configure -l build -d "Configure for building on BUILD" -x
84complete -c configure -l host -d "Cross-compile to build programs to run on HOST" -x
85complete -c configure -l target -d "Configure for building compilers for TARGET" -x
86
87# use autoconf's --help to generate completions:
88complete -c configure -a '(for tok in (commandline -xpc)
89    if string match -q "*configure" -- $tok
90        __fish_parse_configure $tok
91        break
92    end
93end)'