fork/fish-shell

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

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.4 KiB43 linesraw
1# localization: skip(private)
2function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing
3    # How many non-option tokens we skip in the input commandline before completing the subcommand
4    # Usually 1; use "--fcs-skip=2" to make it 2 (see e.g. tmux and ssh completions)
5    set -l skip_next 1
6    set -l subcommand
7    while string match -rq -- '^--[a-z]' $argv[1]
8        set -l arg $argv[1]
9        set -e argv[1]
10        switch $arg
11            case '--fcs-skip=*'
12                set skip_next (string split = -- $arg)[2]
13            case --commandline # --commandline means to use our arguments instead of the commandline.
14                complete -C "$argv"
15                return
16        end
17    end
18    set -l options_with_param $argv
19
20    set -l cmd (commandline -cxp | string escape) (commandline -ct)
21    while set -q cmd[1]
22        set -l token $cmd[1]
23        set -e cmd[1]
24        if contains -- $token $options_with_param
25            set skip_next (math $skip_next + 1)
26            continue
27        end
28        switch $token
29            case '-*' '*=*'
30                continue
31            case '*'
32                if test $skip_next -gt 0
33                    set skip_next (math $skip_next - 1)
34                    continue
35                end
36                # found the start of our command
37                set subcommand $token $cmd
38                break
39        end
40    end
41
42    printf "%s\n" (complete -C "$subcommand")
43end