-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add 'zsh' tab completion #30
Open
wintermi
wants to merge
1
commit into
stefanmaric:next
Choose a base branch
from
wintermi:next
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not from g.
zsh has a cache policy feature in its completion system. Let's try to use that instead and call
g list-all