Skip to content

Instantly share code, notes, and snippets.

@blinsay
Last active December 16, 2015 04:29
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 blinsay/5377663 to your computer and use it in GitHub Desktop.
Save blinsay/5377663 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Apparently this doesn't work. :((((((((((((
_path_remove () { export PATH=`echo -n $PATH | awk -v RS=: -v ORS=: '$0 != "'$1'"' | sed 's/:$//'`; }
goenv() {
new_env=${1:-`pwd`}
old_env=$GOPATH
if [[ -z $old_env ]]; then
_path_remove $old_env/bin
fi
export GOPATH=$new_env
export PATH="$PATH:$new_env/bin"
}
# This works happily.
function goenv() {
case $1 in
"list")
echo "-> gopath=$GOPATH"
;;
*)
_set_goenv $@
;;
esac
}
function _set_goenv() {
new_env=$1
old_env=$GOPATH
if [[ -n $old_env ]]; then
old_bin_path=${old_env}/bin
path=(${path#$old_bin_path})
fi
if [[ -z $new_env ]]; then
new_env=$(pwd)
fi
path+=($new_env/bin)
GOPATH=$new_env
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment