ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

fido

by nerdo ST2/ST3

Run commands when files within a Sublime Text (v2 or v3) project are saved.

Details

  • 2013.07.17.14.56.07
  • github.​com
  • github.​com
  • 6 years ago
  • 46 minutes ago
  • 6 years ago

Installs

  • Total 99
  • Win 28
  • OS X 39
  • Linux 32
Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12 Jun 11 Jun 10 Jun 9 Jun 8 Jun 7 Jun 6 Jun 5 Jun 4 Jun 3 Jun 2 Jun 1 May 31 May 30 May 29 May 28 May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OS X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Fido

Fido is a plugin for Sublime Text (versions 2 and 3) for running commands when files within a project are saved.

Installation

The easy way is to use Package Control.

The “hard” way is to install Fido manually using git. First, go to your Packages subdirectory under Sublime Text's data directory: * Windows %APPDATA%\Sublime Text 2 or %APPDATA%\Sublime Text * OS X: ~/Library/Application Support/Sublime Text 2 or ~/Library/Application Support/Sublime Text * Linux ~/.config/sublime-text-2 or ~/.config/sublime-text * Portable Installation: Sublime Text 2/Data or Sublime Text/Data

Then clone this repository:

git clone git://github.com/nerdo/fido.git

Usage

Fido works by looking for things to do in your project whenever a file is saved. The simplest setup is to have a top-level fido command that is run whenever a file is saved on any of the paths defined within your project. For example, your project file may look like this:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project"
        },
        {
            "path": "/another/path"
        }
    ],
    "fido": "cake build"
}

This configuration runs cake build when a file is saved on one of the project paths defined by folders. The command sets the working directory to the folder the saved file was found on, so if you saved a file in /another/path/scripts/file.coffee, the cake build is run from /another/path.

You can see Fido at work if you open your console.

fido$ cake build
This is the output of cake build!

You can also set separate commands for each folder:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project",
            "fido": "cake build"
        },
        {
            "path": "/another/path",
            "fido": "rm -f ./tmp/generated-output.txt"
        }
    ]
}

In this example, cake build is only run when a file in /my/sublime/project is saved. When a file is saved. When a file is saved on the path /another/path, the file /another/path/tmp/generated-output.txt is deleted with the command rm -f ./tmp/generated-output.txt.

What if you wanted to run cake build on all paths, but only remove that temp file when files within /another/path is saved? No problem. Define your settings like this:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project"
        },
        {
            "path": "/another/path",
            "fido": "rm -f ./tmp/generated-output.txt"
        }
    ],
    "fido": {
        "command": "cake build",
        "alwaysRun": true
    }
}

In this scenario, the Fido command is defined as an object with the properties command and alwaysRun.

If alwaysRun was set to false (the default), the command would not run when a more specific command is found (like the removal of the temp file).

Most projects are set up with a single folder, but you may want to run different commands for files saved in different parts of the project. That can be accomplished by setting up fido as an array. A more real-world project might look something like this:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project"
        },
    ],
    "fido": [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project/scripts/coffee",
            "command": "cake build"
        },
        {
            "path": "/my/sublmime/project/scss",
            "command": "sass --style compressed site.scss ../css/site.css"
        },
        {
            "command": "growlnotify -m'Insanely annoying message every time a file is saved' -t'Annoying Notification'",
            'alwaysRun': true
        }
    ]
}

This sets up Fido to run a few commands. First, cake build runs when files are saved on the path /my/sublime/projects/scripts/coffee. Note the follow_symlinks option has the same meaning as when it is defined in a folder.

Then there is a sass command that gets run to recompile an scss file into css when files are saved on its path.

Last, but not least, there is a command that is run on every file saved within the project which runs growlnotify, for no apparent reason… Ok, so this isn't completely a real-world example :P

Because most people don't normally launch sublime from the command line, it's likely that your environment path won't be set as you expect it. For example, you may see something like this in your console if you were trying to run cake build:

fido$ cake build
/bin/sh: cake: command not found

If you get errors like this, you'll need to set your environment path, open a terminal and check your PATH variable.

In OS X and *nix: echo $PATH

Copy that value, and set it up like so:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project"
        },
    ],
    "fido": [
        {
            "follow_symlinks": true,
            "path": "/my/sublime/project/scripts/coffee",
            "command": "cake build",
            "env": {
                "PATH": "<<< PATH COPIED FROM COMMAND LINE HERE >>>"
            }
        },
        {
            "path": "/my/sublmime/project/scss",
            "command": "sass --style compressed site.scss ../css/site.css",
            "env": {
                "PATH": "<<< PATH COPIED FROM COMMAND LINE HERE >>>"
            }
        },
        {
            "command": "growlnotify -m'Insanely annoying message every time a file is saved' -t'Annoying Notification'",
            'alwaysRun': true,
            "env": {
                "PATH": "<<< PATH COPIED FROM COMMAND LINE HERE >>>"
            }
        }
    ]
}

You may or may not need to set the path depending on where the command lives on your filesystem, but it's probably a good idea to include it with each command.

By the way, any environment variables can be set this way by setting key-value pairs on the env object, not just PATH.

Special Thanks

Special thanks go out to titoBouzout for letting me use a piece of his code from his SideBarEnhancements plugin to get this working properly on ST2.