Sublime Forum

How to Set Environment Var for Git


When I commit from within Sublime Merge it fails…

The failure is due to a precommit hook which uses an environment variable which Sublime Merge does not know. The commit works when I try directly on CLI.

Here is a portion of the precommit…

cd $SOME_ENV_VAR/tests

How can I set an environment variable in Sublime Merge?



Merge should be inheriting the environment of the process that launches it, I would think. What OS are you on?

Windows, applications always get a copy of the global environment.

Linux applications inherit the environment of their parent, which would be the launcher task of your window manager, or the environment that’s current in your shell if you launch applications from the Terminal.

On MacOS applications have a constrained environment on purpose, which is inherited from the application launcher; the launcher does not share the full environment.

For this reason, on MacOS Sublime Text will launch a shell behind the scenes and gather the environment, I would assume that Merge does the same thing, though I can’t verify that at the moment.



I am using MacOS.



Do you get a different result if you start Merge from a terminal (while it’s not running) versus starting it from the launcher?



Launching from command line works! Thanks.

For the record I setup running from the command line like this…

# Do once...
> ln -sv "/Applications/Sublime" /usr/local/bin/smerge

# Then can do...
> smerge


If that works, then something to investigate is if the environment variables you expect to be present are set in .zshrc or in .zprofile, and move them to .zprofile if that’s not where they are.

If that’s the case, swapping that location should let you launch from the dock and still have things work.



Also potentially helpful: