File: __fish_complete_subcommand.fish

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (43 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# localization: skip(private)
function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing
    # How many non-option tokens we skip in the input commandline before completing the subcommand
    # Usually 1; use "--fcs-skip=2" to make it 2 (see e.g. tmux and ssh completions)
    set -l skip_next 1
    set -l subcommand
    while string match -rq -- '^--[a-z]' $argv[1]
        set -l arg $argv[1]
        set -e argv[1]
        switch $arg
            case '--fcs-skip=*'
                set skip_next (string split = -- $arg)[2]
            case --commandline # --commandline means to use our arguments instead of the commandline.
                complete -C "$argv"
                return
        end
    end
    set -l options_with_param $argv

    set -l cmd (commandline -cxp | string escape) (commandline -ct)
    while set -q cmd[1]
        set -l token $cmd[1]
        set -e cmd[1]
        if contains -- $token $options_with_param
            set skip_next (math $skip_next + 1)
            continue
        end
        switch $token
            case '-*' '*=*'
                continue
            case '*'
                if test $skip_next -gt 0
                    set skip_next (math $skip_next - 1)
                    continue
                end
                # found the start of our command
                set subcommand $token $cmd
                break
        end
    end

    printf "%s\n" (complete -C "$subcommand")
end