Show GOPATH in Your Shell Prompt

Jun 6 2014

I use gpm and gvp to set and manage my $GOPATH. What this means is that I frequently change the value of my $GOPATH variable. So it's nice to be able to see the value of $GOPATH in some convenient form in my shell prompt ($PS1).

But I don't want the entire path -- just enough to indicate which project. Given my $GOPATH structure, that just means that I need the name of the last part on the last directory of the $GOPATH:

☃ @Matts-MacBook-Pro.local ~SUGAR «myproject» ‹rc›
⇒                                 ^^^^^^^^^^^

The noted part above shows that my $GOPATH is pointing to the myproject project.

To show that, my prompt command has something like this: $(basename ${GOPATH##*:}). This shows just the folder name on the local folder.