Skip to content

Instantly share code, notes, and snippets.

@13k
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 13k/964039295699086c4593 to your computer and use it in GitHub Desktop.
Save 13k/964039295699086c4593 to your computer and use it in GitHub Desktop.
# Based on chruby's auto feature
# https://github.com/postmodern/chruby/blob/bfd78880fbbbf13635e1f97f83225c6a03ca6e89/share/chruby/auto.sh
function gvm_auto() {
local dir="$PWD/" version
until [[ -z "$dir" ]]; do
dir="${dir%/*}"
if { read -r version <"$dir/.go-version"; } 2>/dev/null || [[ -n "$version" ]]; then
version="${version%%[[:space:]]}"
if [[ "$version" == "$GVM_AUTO_VERSION" ]]; then return
else
GVM_AUTO_VERSION="$version"
if echo "$version" | grep -q "@"; then
local name="${version%@*}"
local pkgset="${version#*@}"
gvm use "$name" > /dev/null && \
gvm pkgset use "$pkgset" > /dev/null
else
gvm use "$version" > /dev/null
fi
return $?
fi
fi
done
if [[ -n "$GVM_AUTO_VERSION" ]]; then
unset GVM_AUTO_VERSION
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment