aboutsummaryrefslogtreecommitdiff
path: root/completions/bun.zsh
blob: 13801931e89ac4ae708287c8237d27316da4920e (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__bun_first_cmd() {
    echo "${words[2]}"
}

__bun_first_cmd_arg() {
    echo "${words[3]}"
}

__bun_arg_count() {
    echo "$#words"
}

_bun_run() {
    if [[ ("$(__bun_arg_count)" = "2") ]]; then
      local -a options
        options=(${(f)"$(SHELL=zsh bun getcompletes)"})

        _describe 'values' options
    elif [[ ("$(__bun_arg_count)" = "3") ]]; then
        local -a run
        run=("${(f)"$(SHELL=zsh bun getcompletes g)"}")
        compadd $run
    else
        _files
        return
    fi

    # Make sure we don't run default completion
    custom_completion=true
}

_bun() {

    # Store custom completion status
    local custom_completion=false

    # Load custom completion commands
    case "$(__bun_first_cmd)" in
    create)
        _files
        return;
        ;;
    dev)
        return;
        ;;
    bun)
        _files
        return;
        ;;
    upgrade)
        return;
        ;;
    discord)
        return;
        ;;
    run)
        _bun_run
        return;
        ;;
    esac

    # Fall back to default completion if we haven't done a custom one
    [[ $custom_completion = false ]] && _bun_run
}

compdef _bun bun