Skip to content

Instantly share code, notes, and snippets.

@raytroop
Last active September 1, 2019 13:51
Show Gist options
  • Save raytroop/ef19fd2f47d05974e6540025ba1fdca9 to your computer and use it in GitHub Desktop.
Save raytroop/ef19fd2f47d05974e6540025ba1fdca9 to your computer and use it in GitHub Desktop.
automatic detect gopath
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