#!/usr/bin/env bash
if [ "$#" -ne 2 ]; then
  echo "mkgoenv GO_IMPORT PATH"
  exit 1
fi

mkdir -p $2/src/$1

cat <<EOF  > $2/activate.sh
# Absolute path this script is in. /home/user/bin
cd "\`dirname '\${BASH_SOURCE:-\$0}'\`"
SCRIPTPATH="\`pwd\`"
echo \$dir
cd - > /dev/null

export GOPATH=\$SCRIPTPATH
#export GOOS="linux"
#export GOARCH="amd64"

gocode set lib-path \$SCRIPTPATH
cd src/$1
EOF

export ppwd=`readlink -f $2`
cat <<EOF > $2/.dir-locals.el
((nil . ((eval . (setenv "GOPATH" "$ppwd")))))
EOF

git clone https://$1 $2/src/$1
