Skip to content

Instantly share code, notes, and snippets.

@jamiehannaford
Created September 6, 2013 12:32
Show Gist options
  • Save jamiehannaford/6463138 to your computer and use it in GitHub Desktop.
Save jamiehannaford/6463138 to your computer and use it in GitHub Desktop.
The convention for Go working environments is to clump everything in one "Gopath" - which kind of acts as a universal environment. But I don't like that; if I'm working on multiple Git projects, I might want a completely separate environment with separate packages and a src directory just for my project. Maybe I'm wrong but this seems to work. N…
#!/bin/bash
subdir=${1%/}
if [ ! $subdir ]; then
echo "Please specify an argument"
exit
fi
dir="${PWD}/$subdir"
if [ ! -d "$dir" ]; then
echo "$dir does not exist"
exit
fi
stripped=$(echo ${PATH} | awk -v RS=: -v ORS=: "/${GOPATH##*/}/ {next} {print}" | sed 's/:*$//')
if [ ! $stripped ]; then
stripped=$PATH
fi
export GOPATH=$dir
export PATH=$stripped:$dir/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment