Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikeekips/5098fb5a6ce4b351f5ac to your computer and use it in GitHub Desktop.
Save spikeekips/5098fb5a6ce4b351f5ac to your computer and use it in GitHub Desktop.
`gopkgcd logging` will change the directory to that source repository.

gopkg

$ env | grep GOPATH
GOPATH=/Users/spikeekips/workspace/kasi

Installed pakcages

$ find ./src -depth 3
./src/code.google.com/p/go-uuid
./src/github.com/alecthomas/units
./src/github.com/BurntSushi/toml
./src/github.com/golang/groupcache
./src/github.com/moraes/config
./src/github.com/op/go-logging
./src/github.com/robertkrimen/otto
./src/github.com/seanpont/assert
./src/github.com/spikeekips/kasi
./src/golang.org/x/tools
./src/gopkg.in/alecthomas/kingpin.v1
./src/launchpad.net/~niemeyer/goyaml

Install gopkg.sh

$ source gopkg.sh

change directory to the go-uuid

$ gosrccd go-uuid

change directory by pakcage name

$ gopkgcd logging
$ pwd
.../src/github.com/op/go-logging
# $
go_find_pkg () {
find $GOPATH/pkg -type f -name "*.a" -exec grep -aH "^package \<$1\>$" {} \; | awk -F":" '{print $1}' | sort | head -n 1
return 0
}
go_find_src () {
max=10
n=1
while [ 1 ]
do
p=$(find $GOPATH/src -type d -depth $n | grep -v '\.git\/' | grep "\<$1\>$" | grep -v grep | sort | head -n 1)
if [ ! -z "${p}" ];then
echo "$p"
return 0
fi
n=$(expr $n + 1)
if [ $n -gt $max ];then
return 1
fi
done
return 0
}
gopkgcd () {
p=$(go_find_pkg $1)
if [ -z "${p}" ];then
return 1
fi
path=$(echo "${p}" | sed -e 's/\.a$//g' -e 's/\/pkg\/[a-z0-9_\-][a-z0-9_\-]*\//\/src\//g')
cd "${path}"
return 0
}
gosrccd () {
p=$(go_find_src $1)
if [ -z "${p}" ];then
echo "[ee] nothing found"
return 1
fi
cd "${p}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment