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

fido

by nerdo ALL

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
  • 11 years ago
  • 17 minutes ago
  • 11 years ago

Installs

  • Total 135
  • Win 47
  • Mac 50
  • Linux 38
Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16 Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Mac 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.