Skip to content

Instantly share code, notes, and snippets.

@renier
Last active March 16, 2018 17:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renier/2eba43072057172cde88dc9167e7de7b to your computer and use it in GitHub Desktop.
Save renier/2eba43072057172cde88dc9167e7de7b to your computer and use it in GitHub Desktop.
gowo - Go workspace switcher
# Usage: gowo my_go_workspace
# Will set GOPATH and update PATH with the bin dir. Will remove previous GOPATH bin dir from the PATH.
# Opinionated about the root dir where Go workspaces go. Change if you want.
# Put this in your ~/.bash_profile
export GOPATH=$HOME/Projects/go
export PATH=$PATH:$GOPATH/bin
function gowo() {
if [ -n "$GOPATH" ]; then
paths=""
for p in `echo $PATH | sed -e 's/:/ /g'`; do
if [ "$p" != "$GOPATH/bin" ]; then
paths+="$p:"
fi
done
export PATH=`echo $paths | sed -e 's/:$//'`
fi
if [ -z "$1" ]; then
export GOPATH=$HOME/Projects/go
else
export GOPATH=$HOME/Projects/$1
fi
export PATH=$PATH:$GOPATH/bin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment