Skip to content

Instantly share code, notes, and snippets.

@selam
Last active March 2, 2016 21:55
Show Gist options
  • Save selam/e3449c075fd047d32454 to your computer and use it in GitHub Desktop.
Save selam/e3449c075fd047d32454 to your computer and use it in GitHub Desktop.
auto add current directory in to GOPATH
export GOPATH="$HOME/.go"
_gopath_auto_activate() {
if [ -e "main.go" ]; then
# Check to see if already activated to avoid redundant activating
FINDED=false
PWD=$(pwd -P)
array=(${GOPATH//:/ })
for p in "${!array[@]}"; do
if [[ "${array[p]}" == "$PWD" ]]; then
FINDED=true
fi;
done;
if [[ $FINDED != true ]]; then
export GOPATH="$GOPATH:$PWD"
fi;
fi
}
export PROMPT_COMMAND=_gopath_auto_activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment