From f24d4bd36cf5d1a626e6e06a208569742044445a Mon Sep 17 00:00:00 2001 From: Greg Wang Date: Thu, 8 Jul 2021 01:20:19 +0000 Subject: [PATCH] feat(goenv): adding new plugin for 'goenv' --- plugins/goenv/README.md | 15 ++++++++++++ plugins/goenv/goenv.plugin.zsh | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 plugins/goenv/README.md create mode 100644 plugins/goenv/goenv.plugin.zsh diff --git a/plugins/goenv/README.md b/plugins/goenv/README.md new file mode 100644 index 000000000..2045d60f8 --- /dev/null +++ b/plugins/goenv/README.md @@ -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. diff --git a/plugins/goenv/goenv.plugin.zsh b/plugins/goenv/goenv.plugin.zsh new file mode 100644 index 000000000..c974d8d92 --- /dev/null +++ b/plugins/goenv/goenv.plugin.zsh @@ -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