summaryrefslogtreecommitdiff
path: root/config/essentials/zsh/completions/_g
blob: 31e60d03c5fa839263e10145941b3a3e1562b6ff (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#compdef g

# -----------------------------------------------------------------------------
# Copyright 2023, Matthew Winter
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for g (https://github.com/stefanmaric/g).
#
# -----------------------------------------------------------------------------
#
# https://github.com/wintermi/zsh-golang
#
# -----------------------------------------------------------------------------

_g() {
    local line state

    _arguments -C \
        "1: :->cmds" \
        "*::arg:->args"

    case "$state" in
        cmds)
            _values "g command" \
                "install[Download and set the go <version>]" \
                "download[Download go <version>]" \
                "remove[Remove the given versions]" \
                "run[Run a given version of go]" \
                "set[Switch to go <version>]" \
                "which[Output bin path for <version>]" \
                "prune[Remove all versions except the current version]" \
                "list[Output downloaded go versions]" \
                "list-all[Output all available, remote go versions]" \
                "self-upgrade[Upgrades g to the latest version]" \
                "help[Display help information, same as g --help]" \
            ;;
        args)
            case $line[1] in
                download)
                    __remoteVersions
                    ;;
                install)
                    _alternative \
                        'args:latest:(latest)' \
                        __remoteVersions
                    ;;
                remove | run | set | which)
                    __installedVersions
                    ;;
                *)
                    ;;
            esac
            ;;
    esac
}

# Completing list of Installed Versions
__installedVersions() {
  declare -a installed_versions_cmd
  installed_versions_cmd=( $(ls -r "$GOROOT/.versions") )
  _describe 'Installed Versions' installed_versions_cmd  -o nosort
}

# Completing list of Remote Versions
__remoteVersions() {
  declare -a remote_versions_cmd
  remote_versions_cmd=( $(cat "$HOME/.cache/zsh-golang/go_versions") )
  _describe 'Remote Versions' remote_versions_cmd  -o nosort
}

# TODO: add the completion for the Options

# Completing 'g' Options
__completeOptions() {
    _arguments -s -S -C \
      "(-h,--help)"{-h,--help}"[Display help information and exit]" \
      "(-v,--version)"{-v,--version}"[Output current version of g and exit]" \
      "(-q,--quiet)"{-q,--quiet}"[Suppress almost all output]" \
      "(-c,--no-color)"{-c,--no-color}"[Force disabled color output]" \
      "(-y,--non-interactive)"{-y,--non-interactive}"[Prevent prompts]" \
      "(-o,--os)"{-o+,--os=}"[Override operating system]:string" \
      "(-a,--arch)"{-a+,--arch=}"[Override system architecture]:string" \
      "(u,--unstable)"{-u,--unstable}"[Include unstable versions in list]"
}

_g "$*"

# vim:ft=zsh:et:sts=2:sw=2