Skip to content

Instantly share code, notes, and snippets.

@fbzhong
Last active September 19, 2017 16:08
Show Gist options
  • Save fbzhong/85b6d2173f32e85d1e6c7b590f08d126 to your computer and use it in GitHub Desktop.
Save fbzhong/85b6d2173f32e85d1e6c7b590f08d126 to your computer and use it in GitHub Desktop.
Auto config GOPATH
# auto config GOPATH.
# /home/robin/workspace/src/github.com/
export _OLDGOPATH=${GOPATH}
go-auto-set-gopath() {
curdir=`pwd`
gopath=""
array=(${(s:/:)curdir})
for ele in "${array[@]}" ; do
if [ "${ele}" = "src" ] ; then
break
fi
gopath="${gopath}/${ele}"
done
if [ "${curdir}" = "${gopath}" ] ; then
gopath="${_OLDGOPATH}"
fi
export GOPATH="${gopath}"
# echo "set GOPATH to $GOPATH"
}
add-zsh-hook chpwd go-auto-set-gopath
go-auto-set-gopath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment