Sublime Command-on-Save

I just finished my Sublime Text 3 plugin: Command on Save.
It executes given commands when you save files. From rsyncing to an other machine, pushing to GIT or generating documentation, everything is possible.

Just install the plugin in Sublime Text 3, configure some commands and you’re good to go.
The easiest way to install the plugin is via Sublime Package Control by adding
https://github.com/klaascuvelier/SublimeCommandOnSave as a new repository and installing the plugin “CommandOnSave”.
Alternatively you can just clone the repository into your Sublime Text Packages folder.

Setting up a settings file is pretty straight forward. All you have to do is add a “commands” entry, with the paths you want to execute commands for and the commands themselves (in an array).
Here are some examples:

{
  "commands": {
    // example 1: project is in folder /Users/klaascuvelier/Projects/example/
    // rsync files to other server on save
    "/Users/klaascuvelier/Projects/example/": [
        "rsync -avz /Users/klaascuvelier/Projects/example/ server@server:/home/server/projects/example/ &"
    ],

    // example 2:
    // just run a bash script on save (you can put much more commands in there)
    "/Users/klaascuvelier/Projects/example2/": [
        "/Users/klaascuvelier/Projects/example2/command.sh &"
    ],

    "/Users/klaascuvelier/Projects/Sublime3/SublimeCommandOnSave/": [
        "echo 'hi'",
        "echo 'aloha'"
    ]
  }
}

Feel free to fork and improve, or contact me if you need any help

Note: this version is not compatible with Sublime Text 2, I do have an older version of this plugin available here: ST2-CommandOnSave. But that plugin is not longer maintained.

7,347 Responses to “Sublime Command-on-Save”

  1. Jorge Avila says:

    Hi! nice plugin, there is a way to pass the saved file as parameter to a command?
    Thank you in advance

  2. Andres says:

    Hi,
    Great plugin, but it has one flaw… when command is ran it freezes sublime text 3 for a moment, like 5 seconds.
    Thanks

  3. Victor says:

    Hi

    Thanks again for the good plugin!

    Note: your plugin’s name is SublimeCommandOnSave, package installer won’t find it when writing “CommandOnSave”.

  4. Thanks guys, I’ll try and take a look at the issues asap.

  5. Winston says:

    Worked for me with no probs: Sublime build 3059 on Mac 10.9.2 rsycning to ubuntu 12.04

    Would be nice to post and share settings files.

    One question: is there anyway to say, “only run this cmd when working on this project?”

    Cheers to some amazing work Klaas!

  6. ethaniel says:

    Awesome plugin. How can I get it to run in windows? Can’t figure out the paths.
    + is there any way to use the filename? I want to rsync the file every time I save it, not the whole tree.

  7. delToro says:

    Looks like a great plugin, but I need to run command from another plugin on file save. Can’t figure it out how to write it into settings file. I’m using Minifier plugin and want to minify file (command “minify_to_file”) on save. Can someone help, please?