Last active
September 19, 2017 16:08
-
-
Save fbzhong/85b6d2173f32e85d1e6c7b590f08d126 to your computer and use it in GitHub Desktop.
Auto config GOPATH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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