Created
August 14, 2015 09:32
-
-
Save sharpner/7d255d7a3a81052a42b3 to your computer and use it in GitHub Desktop.
clone and symlink go open source project
This file contains 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
#/!bin/bash | |
repository=github.com | |
if [ -z "$GOPATH" ] ; then | |
echo '$GOPATH not set.' | |
exit 1 | |
fi | |
cd $GOPATH | |
if [ $# -lt 1 ] ; then | |
echo "Usage: goclone group/project [repository]" | |
exit 1 | |
fi | |
if [ ! -z "$2" ] ; then | |
repository=$2 | |
fi | |
group=`echo $1 | cut -f1 -d"/"` | |
project=`echo $1 | cut -f2 -d"/"` | |
if [ -z "$project" ] || [ -z "$group" ] ; then | |
echo "Usage: goclone group/project [repository]" | |
exit 1 | |
fi | |
repo=$1 | |
target=$GOPATH/src/$repository/$group | |
if [ ! -d $target ] ; then | |
mkdir -p $target | |
echo "Created folder "$target | |
fi | |
cd $target | |
git clone git@$repository:$repo.git | |
if [ $? -ne 0 ] ; then | |
echo "Could not clone repository" | |
exit 1 | |
fi | |
symlink=$project | |
cd $GOPATH | |
ln -s $target/$project _$symlink |
you might find adding something like:
# First path
GOPATH=$(echo $GOPATH | cut -d":" -f1)
or
# Last path
GOPATH=$(echo $GOPATH | rev | cut -d":" -f1 | rev)
helpful. I ended up using last path so that by default go get
would dump into my pkgenv but goclone
would dump into my go workspace.
you can use motemen/ghq.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this small snippet checks out any go project to the correct destination in your gopath and creates a symlink to fast access it.
It should be placed within your $PATH environment variable.
goclone go-mgo/mgo
will then create a symlink$GOPATH/_mgo
which points to$GOPATH/src/github.com/go-mgo/mgo
This is particulary useful on own projects.