Last active
September 1, 2019 13:51
-
-
Save raytroop/ef19fd2f47d05974e6540025ba1fdca9 to your computer and use it in GitHub Desktop.
automatic detect 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
function addgopath(){ | |
cwd=$(pwd) | |
newpath="" | |
for tdir in `ls`;do | |
if [ "$tdir" = "src" ];then | |
newpath=${cwd} | |
break | |
fi | |
done | |
if [ -z $newpath ];then | |
temppath=${cwd} | |
while [ ${temppath} != "/" ];do | |
base=$(basename ${temppath}) | |
dir=$(dirname ${temppath}) | |
if [ "${base}" = "src" ];then | |
newpath=${dir} | |
break | |
fi | |
temppath=${dir} | |
done | |
fi | |
if [ ! -z ${newpath} ];then | |
echo "export ${newpath}:${GOPATH}" | |
export GOPATH=${newpath}:${GOPATH} | |
else | |
echo "no valid GOPATH found" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment