mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-23 14:20:08 +00:00
feat(goenv): adding new plugin for 'goenv'
This commit is contained in:
parent
c44b99e901
commit
f24d4bd36c
2 changed files with 57 additions and 0 deletions
15
plugins/goenv/README.md
Normal file
15
plugins/goenv/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# goenv
|
||||
|
||||
This plugin looks for [goenv](https://github.com/syndbg/goenv), a Simple Go-lang version
|
||||
management system, and loads it if it's found.
|
||||
|
||||
To use it, add `goenv` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... goenv)
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
- `goenv_prompt_info`: displays the Go-lang version in use by goenv; or the global Go-lang
|
||||
version, if goenv wasn't found.
|
42
plugins/goenv/goenv.plugin.zsh
Normal file
42
plugins/goenv/goenv.plugin.zsh
Normal file
|
@ -0,0 +1,42 @@
|
|||
# This plugin loads goenv into the current shell.
|
||||
|
||||
# Load goenv only if command not already available
|
||||
if command -v goenv &> /dev/null && [[ "$(uname -r)" != *icrosoft* ]]; then
|
||||
FOUND_GOENV=1
|
||||
else
|
||||
FOUND_GOENV=0
|
||||
fi
|
||||
|
||||
if [[ $FOUND_GOENV -ne 1 ]]; then
|
||||
goenvdirs=("$HOME/.goenv" "/usr/local/goenv" "/opt/goenv" "/usr/local/opt/goenv")
|
||||
for dir in $goenvdirs; do
|
||||
if [[ -d $dir/bin ]]; then
|
||||
export PATH="$PATH:$dir/bin"
|
||||
FOUND_GOENV=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $FOUND_GOENV -ne 1 ]]; then
|
||||
if (( $+commands[brew] )) && dir=$(brew --prefix goenv 2>/dev/null); then
|
||||
if [[ -d $dir/bin ]]; then
|
||||
export PATH="$PATH:$dir/bin"
|
||||
FOUND_GOENV=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $FOUND_GOENV -eq 1 ]]; then
|
||||
eval "$(goenv init -)"
|
||||
function goenv_prompt_info() {
|
||||
echo "$(goenv version-name)"
|
||||
}
|
||||
else
|
||||
# fallback to system python
|
||||
function goenv_prompt_info() {
|
||||
echo "system: $(go verson 2>&1 | cut -f 3 -d ' ')"
|
||||
}
|
||||
fi
|
||||
|
||||
unset FOUND_GOENV goenvdirs dir
|
Loading…
Reference in a new issue