Last active
November 2, 2017 09:28
-
-
Save farnasirim/fa4f7ab61a6944e214df6b9fd6525cd9 to your computer and use it in GitHub Desktop.
navigate to a go project directory easily using `goto` command
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 | |
if [ -z "$@" ]; then | |
echo "Usage: goto project-name" | |
return | |
fi | |
search_path=$GOPATH/src/ | |
for i in {1..3}; do | |
len=${#search_path} | |
project_dir=$(find $GOPATH/src -maxdepth $i -mindepth $i | cut -c$len- | grep -m 1 $1) | |
if [ ! -z "$project_dir" ] ; then | |
cd $search_path/$project_dir | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful 👍