Sublime Forum

EnvironmentSettings. Define a set of environment variables in the .sublime_project file

#1

Hi,

I have created a plugin to set environment variables per project.

The variables can be set in the “settings” part of a .sublime-project file.
Here two entries can be created:

  • env_file to point to an external shell file. If this file sets variables, those variables will be set also in Sublime.
    Paths can be relative to the project file itself (ex: “…/…/env.sh”)
  • env is a dictionary. Each key:value pair will be set as environment variable.

Both the entries can, actually must, specify which operative system the variables are for.
the possible values are the ones returned by the Python’s function platform.system(). The value may change depending on the system you are but
the common and most probable are:

  • Linux
  • Darwin (Mac OSX)
  • Windows

At least one must be present.

For example:

{
  "folders":
  [
    {
      "path": "my/path"
    }
  ],
  "settings":
  {
    "env_file": 
    {
      "Windows": "%HOME%/Documents/myEnv.bat",
      "Darwin": "~/Documents/myEnv.sh",
      "Linux": "~/Documents/myEnv.sh"
    },
    "env":
    {
      "Windows": 
      {
        "PATH": "%PATH%;%HOME%/Documents/MyTool"
      },
      "Darwin": 
      {
        "PATH": "$PATH:~/Documents/MyTool"
      },
      "Linux": 
      {
        "PATH": "$PATH:~/Documents/MyTool"
      }
    }
  }
}

If you are interested to know more please look at this page on PackageControl here or at the Bitbucket mercurial repository here.

Cheers!

1 Like