Skip to content

Instantly share code, notes, and snippets.

@nelsam
Created January 21, 2015 05:01
Show Gist options
  • Save nelsam/4a8359312c123abc4f0a to your computer and use it in GitHub Desktop.
Save nelsam/4a8359312c123abc4f0a to your computer and use it in GitHub Desktop.
A helper tool to set up a unique $GOPATH for each project I work directly on.
#!/usr/bin/env sh
set -e
development_root=~/dev
goimports="golang.org/x/tools/cmd/goimports"
golint="github.com/golang/lint/golint"
gocode="github.com/nsf/gocode"
if [[ "$#" -ne 1 ]]
then
echo "error: $0 requires the go-gettable project name as an argument"
exit 1
fi
echo "Setting up GOPATH for project $1"
oldGOPATH="${GOPATH}"
proj_name=$(basename "$1")
GOPATH="${development_root}/${proj_name}"
if [[ -e "${GOPATH}" ]]
then
echo "error: ${GOPATH} exists"
exit 1
fi
mkdir "${GOPATH}"
touch "${GOPATH}/.gopath"
ln -s ~"/.emacs.d/gopath-dir-locals.el" "${GOPATH}/.dir-locals.el"
export GOPATH
echo "Installing goimports"
go get "${goimports}"
echo "Installing golint"
go get "${golint}"
echo "Installing gocode"
go get "${gocode}"
echo "Installing $1"
go get "$1"
if [[ "${oldGOPATH}" != "" ]]
then
export GOPATH="${oldGOPATH}"
else
unset GOPATH
fi
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment