Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 52999f6e20ead6f88d2fe77c34db522d6d8c2210 @wfarr committed Jun 15, 2013
@@ -0,0 +1,3 @@
+/shims
+/version
+/versions
@@ -0,0 +1,20 @@
+Copyright (c) 2013 Will Farrington
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
+# goenv
+
+rbenv, but for Go.
+
+## Installation
+
+To install the latest stable release:
+
+```
+git clone -b v0.0.1 https://github.com/wfarr/goenv.git ~/.goenv
+```
+
+Then add the following to your shell config at the end:
+
+```
+export PATH="$HOME/.goenv/bin:$PATH"
+eval "(goenv init -)"
+```
+
+## Usage
+
+```
+» goenv help
+Usage: goenv <command> [<args>]
+
+Some useful goenv commands are:
+ exec Execute a command from a particular Go version.
+ shell Set GOENV_VERSION for the lifetime of a shell.
+ local Persist the preferred Go version in the cwd.
+ global Persist the preferred Go default version.
+ install Install a version of Go.
+ uninstall Uninstall a version of Go.
+ version Show the current Go version.
+ versions Display all versions of Go installed in `${GOENV_ROOT}/versions/*'.
+ rehash Rehash goenv shims (run this after installing executables)
+
+See `goenv help <command>' for information on a specific command.
+```
+
+## Credits
+
+This library was heavily, heavily, heavily inspired by
+[@sstephenson](https://github.com/sstephenson)'s
+[rbenv](https://github.com/sstephenson/rbenv) and
+[ruby-build](https://github.com/sstephenson/ruby-build) projects.
+A few ideas were also taken from [nvm](https://github.com/creationix/nvm).
+
+A number of patterns and utilities are borrowed from that project,
+and it is my hope that goenv provides the same simplicity,
+elegance, and usability that I've come to love in rbenv and ruby-build
+for Go users.
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+
+# goenv version
+version="0.0.0"
+
+# Bomb out if we hit an error, ever
+set -e
+
+# Verbose output in debug mode
+[ -n "$GOENV_DEBUG" ] && {
+ set -x
+}
+
+# Helper functions
+resolve_link() {
+ $(type -p greadlink readlink | head -1) "$1"
+}
+
+abs_dirname() {
+ local cwd="$(pwd)"
+ local path="$1"
+
+ while [ -n "$path" ]; do
+ cd "${path%/*}"
+ local name="${path##*/}"
+ path="$(resolve_link "$name" || true)"
+ done
+
+ pwd
+ cd "$cwd"
+}
+
+# Set up GOENV_ROOT, location where everything lives
+
+if [ -z "${GOENV_ROOT}" ]; then
+ GOENV_ROOT="${HOME}/.goenv"
+else
+ GOENV_ROOT="${GOENV_ROOT%/}"
+fi
+
+export GOENV_ROOT
+
+# Jump into the GOENV_DIR
+if [ -z "${GOENV_DIR}" ]; then
+ GOENV_DIR="$(pwd)"
+else
+ cd "${GOENV_DIR}" 2>/dev/null || {
+ echo "goenv: cannot change working directory to \`$GOENV_DIR'"
+ exit 1
+ } >&2
+
+ GOENV_DIR="$(pwd)"
+
+ cd "$OLDPWD"
+fi
+
+export GOENV_DIR
+
+# Pop the first argument, our subcommand
+command="$1"
+
+# Make sure we can find out utilities on PATH
+bin_path="$(abs_dirname "$0")"
+export PATH="${bin_path}":$PATH
+
+case "$command" in
+ "" | "-h" | "--help" )
+ exec goenv-help
+ ;;
+
+ "-v" | "--version" )
+ echo "goenv ${version}"
+ exit
+ ;;
+
+ *)
+ command_path="${bin_path}/goenv-${command}"
+
+ [ -x "${command_path}" ] || {
+ echo "goenv: no such command \`$command'" >&2
+ exit 1
+ }
+
+ shift 1
+ exec "goenv-$command" "$@"
+ ;;
+esac
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+#
+# Summary: Execute a command from a particular Go version.
+#
+# Usage: goenv exec <command> [<args>]
+#
+# Puts the current Go version onto PATH and runs the specified command.
+
+# Bomb out if we hit an error, ever
+set -e
+
+# Verbose output in debug mode
+[ -n "$GOENV_DEBUG" ] && {
+ set -x
+}
+
+# Set the current Go version
+if [ -z "$GOENV_VERSION" ]; then
+ GOENV_VERSION="$(goenv version)"
+
+ # Couldn't infer from a file either
+ if [ -z "$GOENV_VERSION" ]; then
+ echo "goenv: no \`GOENV_VERSION' configured" >&2
+ exit 1
+ fi
+fi
+
+# if the specified Go version lacks this bin, bail
+if [ ! -x "$GOENV_ROOT/versions/$GOENV_VERSION/bin/$1" ]; then
+ echo "goenv: \`$1' does not exist for $GOENV_VERSION" >&2
+
+ for version in "$(goenv versions)"; do
+ if [ -x "$GOENV_ROOT/versions/$version/bin/$1" ]; then
+ echo " $version" >&2
+ fi
+ done
+
+ exit 1
+fi
+
+export GOENV_VERSION
+
+# Put our bindir onto PATH
+bindir="$GOENV_ROOT/versions/$GOENV_VERSION/bin"
+
+export PATH="$bindir:$PATH"
+
+exec "$@"
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Summary: Persist the preferred Go default version.
+#
+# Usage: goenv global <version>
+# goenv global --unset|-u
+
+# Bomb out if we hit an error, ever
+set -e
+
+# Verbose output in debug mode
+[ -n "$GOENV_DEBUG" ] && {
+ set -x
+}
+
+# Set the version
+version="$1"
+version_file="${GOENV_ROOT}/version"
+
+case "$version" in
+ "")
+ echo "goenv: a version or --unset is required" >&2
+ exit 1
+ ;;
+
+ "-u" | "--unset")
+ if [ -f "$version_file" ]; then
+ rm "$version_file"
+ echo "Unset $version_file"
+ else
+ echo "goenv: no global version to unset" >&2
+ exit 1
+ fi
+ ;;
+
+ *)
+ echo "$version" > "$version_file"
+ echo "Set $version_file to use $version"
+ ;;
+esac
Oops, something went wrong.

0 comments on commit 52999f6

Please sign in to comment.