fork/fish-shell

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

Fabian Boehmcompletions/rustc: Don't autoinstall nightly toolchaindd9784296

master
4.9 KiB94 linesraw
1complete -c rustc -s h -l help
2
3complete -c rustc -x -l cfg
4complete -c rustc -x -l check-cfg -d "Provide list of expected cfgs for checking"
5complete -c rustc -r -s L -a 'dependency= crate= native= framework= all='
6complete -c rustc -x -s l -a 'dylib= static= framework='
7complete -c rustc -x -l crate-type -a 'bin lib rlib dylib cdylib staticlib proc-macro'
8complete -c rustc -r -l crate-name
9complete -c rustc -x -l edition -a '2015 2018 2021' -d "Specify compiler edition"
10complete -c rustc -x -l emit -a 'asm llvm-bc llvm-ir obj link dep-info metadata mir'
11complete -c rustc -x -l print -d "Print compiler information" -xa "(rustc --print fake 2>&1 | string match -arg '`(.*?)`' | string match -v fake)"
12complete -c rustc -s g -d "Equivalent to -C debuginfo=2"
13complete -c rustc -s O -d "Equivalent to -C opt-level=2"
14complete -c rustc -r -s o -d "Write output to <filename>"
15complete -c rustc -r -l out-dir
16complete -c rustc -x -l explain
17complete -c rustc -l test
18complete -c rustc -l target -xa "(rustc --print target-list)"
19complete -c rustc -x -l cap-lints
20complete -c rustc -s V -l version -d 'Print version info and exit'
21complete -c rustc -s v -l verbose -d 'Use verbose output'
22complete -c rustc -f -l extern
23complete -c rustc -f -l sysroot
24complete -c rustc -x -l color -a 'auto always never'
25
26complete -c rustc -s C -l codegen -xa "(rustc -C help 2>/dev/null | string match -rv 'option is deprecated' | string replace -rf -i '(\s+)-C\s*(.+)=val(\s+)--(\s+)([^\n]+)' '\$2='\t'\$5')"
27
28# rustc -Z is only available with the nightly toolchain, which may not be installed
29function __fish_rustc_z_completions
30    # This function takes a little over one second to run, so let's cache it. (It's ok if the first run is slow
31    # since this is only run when specifically completing `rustc -Z<TAB>` and not when the completion is loaded.)
32    if set -q __fish_cached_rustc_z_completions
33        printf '%s\n' $__fish_cached_rustc_z_completions
34        return
35    end
36
37    if not command -q rustup; or not rustup toolchain list | string match -q 'nightly*'
38        return
39    end
40
41    set -l rust_docs (rustc +nightly -Z help 2>/dev/null |
42        string replace -r '^\s+' '' | string replace -ar ' +' ' ' | string replace -r '=val +-- +' '=\t')
43
44    set -f flag
45    set -f docs
46    set -g __fish_cached_rustc_z_completions (for line in $rust_docs
47        # Handle multi-line completions for options with values, e.g.
48        #    -Z                                      unpretty=val -- present the input source, unstable (and less-pretty) variants;
49        # `normal`, `identified`,
50        # `expanded`, `expanded,identified`,
51        # `expanded,hygiene` (with internal representations)
52        if string match -rq '^-Z' -- $line
53            # Actual -Z completion
54            set -l parts (string split -- \t $line)
55            set flag (string replace -r -- '-Z\s*' '' $parts[1])
56            set docs $parts[2]
57            printf '%s\t%s\n' $flag $docs
58        else
59            # Check for possible argument followed by description, supporting multiple completions per line
60            # Don't split on ',' but rather ', ' to preserve commas in backticks
61            # echo $flag:
62            for line in (string split ', ' -- $line | string trim -c ',' | string trim)
63                # echo \* $line
64                if set -l parts (string match -gr '^(?:or )?`=?(.*?)`\s*(?:\((.*?)\)|: (.*))?\s*' -- $line)
65                    set -l docs $parts[2] $parts[3]
66                    printf '%s%s\t%s\n' $flag $parts[1] $docs
67                else if set -l parts (string match -gr '^([a-z-]+):?\s*(.*)' -- $line)
68                    printf '%s%s\t%s\n' $flag $parts[1] $parts[2]
69                end | string match -ev '=val'
70            end
71        end
72    end)
73    __fish_rustc_z_completions
74end
75complete -c rustc -x -s Z -ka "(__fish_rustc_z_completions)"
76
77function __fish_rustc_lint_completions
78    rustc -W help 2>/dev/null \
79        | string match -r \
80        '(?:\s+)(?:.+)(?:\s+)(?:allow|warn|deny|forbid)(?:\s+){2}(?:[^\n]+)' \
81        | string replace -r -i \
82        '(\s+)(.+)(\s+)(allow|warn|deny|forbid)(\s+){2}([^\n]+)' '$2 $6' \
83        | string match -r '^.*[^:]$' \
84        | string match -r -v '^(allow|warn|deny|forbid)$' \
85        | string match -r -v '^([a-z\-]+)(\s+)(allow|warn|deny|forbid)' \
86        | string replace ' ' ,\t
87end
88
89# Support multiple arguments in one parameter as comma-separated values with `__fish_concat_completions`,
90# combined with printing the name with a trailing , above.
91complete -c rustc -s W -l warn -xa "(__fish_rustc_lint_completions | __fish_concat_completions)" -d "Warn on lint"
92complete -c rustc -s A -l allow -xa "(__fish_rustc_lint_completions | __fish_concat_completions)" -d "Allow lint"
93complete -c rustc -s D -l deny -xa "(__fish_rustc_lint_completions | __fish_concat_completions)" -d "Deny lint"
94complete -c rustc -s F -l forbid -xa "(__fish_rustc_lint_completions | __fish_concat_completions)" -d "Forbid lint"