The easiest solution I found for this is to use the build system as a proxy for exec, which then lets you use $file, $file_name, etc.
Go to Tools > Build System > New Build System, copy and paste your old build system into here, or just edit your old build system, and then add a variants section, give it a name, and all the other commands you want. Then add a new keyboard shortcut and add an args with the variant name.
All in all:
David-Go.sublime-build
{
"shell": "true"],
"cmd": "sublime-go-build '$file' '$file_name' '$file_path'"],
"selector": "source.go",
"variants":
{"shell": "true"],
"cmd": "sublime-go-test '$file' '$file_name' '$file_path'"],
"name": "Run"}]
}
User/Default (Linux).sublime-keymap
{ "keys": "ctrl+b"], "command": "build" },
{ "keys": "ctrl+shift+b"], "command": "build", "args": {"variant": "Run"} }
Now when I press ctrl+b with a .go file open it runs the build command which executes my bash script “sublime-go-build” which is in my system’s $PATH with three arguments, $1=$file, etc. If I press ctrl+shift+b it does the same thing with “sublime-go-test” instead. You can add as many variants as you want and set them to whatever keyboard shortcuts that you want. One advantage is that now you can run this only on the language files you want, one disadvantage is that you have to add this to every languages sublime build file.