Sublime Text 3 custom build

By Mathias Westerdahl / 2017-05-28 / In categories notes

Adding a custom build step to Sublime Text 3 is easy.

Simply choose

"Tools -> Build System -> New Build System"

and it will create a new .sublime-build file that you can configure to your liking.

How to configure it, can be found in the Configuration manual.

In my case, I wanted to invoke the file in the project root directory:

// The initial version

{    "cmd": ["sh", ""],    "working_dir": "${project_path:${folder}}"}

Build output

The final output

Next, I needed to capture the output from the compiler, and in this case, it’s from the arduino compilers. Unfortunately, the ansi output they produce couldn’t be handled by either Sublime Text 3 or the plugin ANSIescape. The only solution I managed to conjure up was to install ansifilter and use that.

$ brew install ansifilter

And, since the “cmd” tag doesn’t support more than one command, and because “shell_cmd” doesn’t support “working_dir”, I ended up with this:

// Final version{    "shell_cmd": "cd ${project_path:${folder}} && ./ 2>&1 | ansifilter",    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",    "syntax": "Packages/Makefile/Make Output.sublime-syntax"}

Note that when using the “shell_cmd”, it create a shell for each build. So if you do something time consuming things in your bash startup scripts, it will take extra long time to build in Sublime as well.

You can read more on the subject here

Mathias Westerdahl


Mathias Westerdahl

A game developer since 2001. Currently at