Skip to content

Commit

Permalink
Add a shell function to go to the go module root
Browse files Browse the repository at this point in the history
In Go code with a bunch of different modules hanging around, this can be
rather useful. Also, it helps to be able to open an editor that knows
about the whole module.
  • Loading branch information
dhwthompson committed Jul 31, 2023
1 parent eae5df4 commit 19f1fd4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions zsh/zsh/gomod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function gm {
local modpath=$(go env GOMOD)
if [[ $modpath == "/dev/null" ]]; then
>&2 echo "No go.mod path found"
return 1
fi
local modroot=${modpath%/*}
cd $modroot
>&2 echo $modroot
}

0 comments on commit 19f1fd4

Please sign in to comment.