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
  • 2 hours ago
  • 6 years ago

Installs

  • Total 99
  • Win 28
  • OS X 39
  • Linux 32
Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10
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 1 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.