Go build and install on save in SublimeText3

Update: Turns out every new Go developer makes this mistake. I realized the err of my ways with a week of writing this. When you just accept the Go way, everything gets better. Ignore my stupidity below.

Recently I have been dabbling more and more with go. And I write my go apps in SublimeText3. Soon after starting this I found the awesome SublimeGo plugin. So without knowing much, this makes life a lot easier. What I especially enjoy is the ability to run an argument on save. So every time I save a go file, it can do something. At first this ran a build . errors && go vet. But then I wanted a bit more. I wanted it run that, then if successful build the app and move the compiled app to my bin directory.

Unfortunately, the one sucky part of golang is the opinionated way it wants you to organize your filesystem. If you want to keep all your projects together, then your bin directory is going to be required to be in a certain place. The build command claims to allow an output directory with -o but that doesn’t actually work the way it’s documented.

But I managed to find a workaroud and thought I would share. I just build to the current directory then move the file that has the same name as the current directory to my ~/bin which is already in my path. Its not perfect since a file briefly appears in my ST sidebar, but it works.

Here is my full GoSublime.sublime-settings file: