Sublime Forum

Detect running command from ST or setting Environment variable on All build systems?

#1

Background

My .bashrc file has some components that take a little longer than I’d like on every ST Build System run. Before a recent update, I added a check for the TERM environment and skipped over that slow stuff, and everything was good.

Recently, something changed either in the dev-build or in my config, and now it appears that TERM is now set something that passes if [[ -n $TERM && $TERM != "dumb" ]]; ...

Question

Is there another way I can detect from a script that it’s being executed from ST?

On my custom build systems, I can one-by-one add an environment variable and check for that, but this does nothing for default or plugin build systems and is untenable to keep up with on every build system I write.

For example, can I set an environment variable from the user settings?

0 Likes

#2

You can use the console to modify the environment of the plugin_host process. This would work as a quick-and-dirty solution for debugging. You could also add a Python script in your User directory that does the same thing.

0 Likes

#3

How does one do that?

0 Likes

#4

You can indeed, by using the build_env setting, which works in your Preferences.sublime-settings as well as in the syntax specific settings (should you want to apply a different set of variables/values there for whatever reason).

For example:

Preferences.sublime-settings

"build_env": {
	"VARIABLE": "SOMETHING"
}

Build system

However, this won’t apply to 100% of all build systems. That’s because one of the keys that’s allowed in a sublime-build file is the target key, which tells Sublime that when the build executes, it should use a specific plugin command to run the build. So in that case, it’s up to that command to find and honour this setting.

That said, when that key is not present, the exec command that’s built into Sublime is used by default, and that command respects the value of this setting. It’s also fairly common (I think) for a custom build target to be created that is either based on the exec command or which uses the exec command directly, in which case it would work for those as well.

3 Likes

#5

You have saved me from all sorts of headaches in the future, Thank You!.

Most of the build systems I use, I wrote. But I’ll definitely consider this elsewhere.

0 Likes