https://github.com/emptyless/go-get-zsh-autocomplete
'go get' zsh command completion based on already locally fetched packages in the GOMODCACHE and git ls-remote versions
https://github.com/emptyless/go-get-zsh-autocomplete
autocomplete go golang zsh
Last synced: 4 months ago
JSON representation
'go get' zsh command completion based on already locally fetched packages in the GOMODCACHE and git ls-remote versions
- Host: GitHub
- URL: https://github.com/emptyless/go-get-zsh-autocomplete
- Owner: Emptyless
- License: mit
- Created: 2025-05-07T18:08:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-01T15:22:46.000Z (about 1 year ago)
- Last Synced: 2025-09-19T11:41:59.815Z (9 months ago)
- Topics: autocomplete, go, golang, zsh
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 'go get' zsh autocompletions
Inspired by [spf13/cobra completions](https://github.com/spf13/cobra/blob/main/site/content/completions/_index.md), this
repo reproduces similar autocompletions for the 'go get' command based on already locally fetched
packages in the `GOMODCACHE` and uses `git ls-remote` to fetch possible versions for those packages.
> No issues were found during local development and or local usage but your mileage may vary. The author(s) are not responsible
for any issues that you may encounter or results thereof when using resources from this repository. Usage is 100%
at own risk. Submit issues to the Github issue tracker if found.
## Getting Started
Ensure that `Z Shell` (zsh) and Go are installed, e.g. on linux with apt:
```
apt install zsh
apt install golang
```
Or on Mac with (using [Brew](https://brew.sh)):
```
brew install zsh
brew install go
```
Commpletions are based on the `GOMODCACHE` location, if `go` was just installed, verify this location
using `go env GOMODCACHE`
To use ZSH autocompletions, the autocompletion system must have been initialized. If not, ensure that the
following is part of your `~/.zshrc`
```
autoload -Uz compinit
compinit
```
Install the completions using 1 of 2 methods:
1) by appending the file to some `$fpath`, e.g. in `~/.zshrc`:
```
git clone https://github.com/Emptyless/go-zsh-autocomplete
echo "" >> ~/.zshrc
cat go-zsh-autocomplete/_go-zsh-autocomplete.zsh >> ~/.zshrc
```
2) by referencing the _go-zsh-autocomplete.zsh file
```
git clone https://github.com/Emptyless/go-zsh-autocomplete
echo "" >> ~/.zshrc
echo -n "source " >> ~/.zshrc
pwd | tr -d '\n' >> ~/.zshrc
echo "go-zsh-autocomplete/_go-zsh-autocomplete.zsh" >> ~/.zshrc
echo "" >> ~/.zshrc
```
Source the zshrc:
```
source ~/.zshrc
```
And now for any package that is in the GOMODCACHE (see `go env GOMODCACHE`), autocompletion is enabled:
```
go get github
```
will display all locally cached Github packages. For some and , fetch the tags and branches using:
```
go get github.com//@
```
which will display all possible branches and tags to use for `go get`
## Oh My ZSH
When using [Oh My Zsh](https://ohmyz.sh), there is a recommended location to store completions:
```
git clone github.com/Emptyless/go-zsh-autocomplete
echo '#!/bin/sh\n' > ~/.oh-my-zsh/completions/_go-zsh-autocomplete.zsh
cat ./go-zsh-autocomplete/_go-zsh-autocomplete.zsh >> ~/.oh-my-zsh/completions/_go-zsh-autocomplete.zsh
chmod +x ~/.oh-my-zsh/completions/_go-zsh-autocomplete.zsh
```
## Debugging
Ensure that the `$ZSH_GO_COMP_DEBUG_FILE` variable is set to some filepath, e.g.
```
export ZSH_GO_COMP_DEBUG_FILE=debug.txt
go get github.com/
```
## Development
Add the zsh shebang before development and set the debug variable
```
#!/bin/zsh
export ZSH_GO_COMP_DEBUG_FILE=debug.txt
```