Skip to content

Instantly share code, notes, and snippets.

@sliminality
Last active July 6, 2017 17:32
Show Gist options
  • Save sliminality/62e087a271868270843295c63c2b98ff to your computer and use it in GitHub Desktop.
Save sliminality/62e087a271868270843295c63c2b98ff to your computer and use it in GitHub Desktop.
Sublime project config reference

Build system arguments

Argument Example Notes
cmd ['python', '-m', '$project'] Required if shell_cmd is empty; overridden by shell_cmd; searched in PATH
shell_cmd yarn build Required if cmd is empty; overrides cmd
working_dir ?? Temporarily change to directory before executing cmd
env { EDITOR: 'vim' }? Can merge in a dictionary before passing to cmd; expands environment variables.
shell true Runs cmd through the shell if true; noop if shell_cmd is used
path /User/sarah/git Used by cmd; expands environment variables.

Build system variables

Expanded in cmd, shell_cmd, and working_dir.

Variable Example Description
$file_path /User/sarah/git/dtr/chrome-remote-css Full path to directory of current file
$file /User/sarah/git/dtr/chrome-remote-css/src/main.js Full path to current file
$file_name main.js Name of current file
$file_extension js Extension of current file
$file_base_name main Name of current file, without extension
$folder ?? Path to the first folder opened in current project
$project_path /User/sarah/git/dtr Full path to directory current .sublime-project file
$project_name chrome-remote-css Name of current .sublime-project file

Build system template features

${project_name:Default}

Name of the current project if there is one, otherwise Default.

${file/\.php/\.txt/}

Full path of the current file, replacing .php with .txt.

Nice extras

Colorized output

Replace ANSI escape codes with nice colors using SublimeANSI and adding the following to your build system:

{
  "name": "Nicely colored build system",  // obviously change this to whatever
  // ...
  "target": "ansi_color_build",
  "syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}

Get to root of current repository

For situations where $project_path doesn't cut it, use

git rev-parse --show-toplevel

to get to the root of the current git repository. So:

{
  // ...
  "shell_cmd": "cd `git rev-parse --show-toplevel` && <YOUR BUILD COMMAND HERE>"
}
{
"folders":
[
{
"path": "./chrome-remote-css"
}
],
"build_systems": [
{
"name": "Yarn build",
// Use `git rev-parse --show-toplevel` to get to root of current git repo
// Could also do
// "shell_cmd": "cd $project_path && yarn build",
"shell_cmd": "cd `git rev-parse --show-toplevel` && yarn build",
"path": "~/git/dtr/chrome-remote-css",
// Colorize output using https://github.com/aziz/SublimeANSI
"target": "ansi_color_build",
"syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment