Skip to content

Instantly share code, notes, and snippets.

@carolynvs
Last active July 10, 2020 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carolynvs/11227e93d4c6080b72440c55f635a98b to your computer and use it in GitHub Desktop.
Save carolynvs/11227e93d4c6080b72440c55f635a98b to your computer and use it in GitHub Desktop.
Find a go project in your GOPATH, written by @steder
#!/usr/bin/env bash
# Just source this file or copy/paste this function in your ~/.bashrc or ~/.bash_profile
function gof {
if (( $# == 0 )); then
echo "usage: $gof <dir>"
echo "jumps to $GOPATH/src directory matching <dir>"
return
fi
GOPATH=${GOPATH:-~/go}
PKGDIR=$(find $GOPATH/src -type d -maxdepth 3 -iname "$1" | sort | head -n 1)
if [[ -d $PKGDIR ]]; then
cd $PKGDIR
else
echo "No go path in $GOPATH matching $1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment