/ExecuteOnSave

Sublime Text 2 Plugin, execute command(s) when you save a specific file in Sublime Text 2.

Primary LanguagePython

ExecuteOnSave Sublime Text 2 Plugin

This simple plugin executes a command or multiple commands when a specific file is saved.
(Inspired by https://github.com/alexnj/SublimeOnSaveBuild)

Installation

Without Git: Download the latest source from GitHub and copy the ExecuteOnSave folder to your Sublime Text 2 "Packages" directory.

With Git: Clone the repository in your Sublime Text 2 "Packages" directory:

git clone git://github.com/alexnj/ExecuteOnSave.git

The "Packages" directory is located at:

  • OS X:

      ~/Library/Application Support/Sublime Text 2/Packages/
    
  • Linux:

      ~/.config/sublime-text-2/Packages/
    
  • Windows:

      %APPDATA%/Sublime Text 2/Packages/
    

Configuration

There are a number of configuration options available to customize the behavior of ExecuteOnSave. For the latest information on what options are available, select the menu item Preferences->Package Settings->ExecuteOnSave->Settings - Default.

Do NOT edit the default ExecuteOnSave settings. Your changes will be lost when ExecuteOnSave is updated. ALWAYS edit the project ExecuteOnSave settings by selecting Project->Edit Project.

  • build_on_save Set to 1 to trigger a build on save. By default, this is set to 0.

  • filter_execute Is a dictionary that holds one or multiple paths along with its associated command executions. Each key is a regular expression that specifies on which files that are saved the command should be executed. The value is the args to the the command that should be executed. Okay this sounds way too complicated, an example should clear this up.

Example project file:

{
	"folders":
	[
		{
			"path": "/Users/username/Sites/projects/flow2/repo"
		}
	],
	"settings":
	{
		"build_on_save": 1,
		"filter_execute": {
			"\\.js$": { "cmd": "/Users/username/Sites/projects/flow2/repo/build.sh" },
			"\\.as$": { "cmd": "/Users/username/Sites/projects/flow2/repo/flash/build.sh" }
		}
	}
}

In this case javascript files that are saved trigger an execution of the ..repo/build.sh file and actionscript files that are saved trigger an execution of the ..repo/flash/build.sh.

It's also possible to execute the commands with a keyboard combo instead of on every save. This is handy for commands that take a lot of time. For example, I have this in my Preferences->Key Bindings - User.

[
	{ "keys": ["ctrl+z"], "command": "execute_on_save" }
]