Sublime Forum

How can i run a script with the same path Sublimetext uses to load a plugin?

#1

I am a beginner and struggling with my python paths. What i am trying to do is running my test scripts close to how SublimeText is running the plugin, since my tests don’t depend on Sublime API.

I tried changing my working directory to "working_dir": "$USER/.config/sublime-text-3/Packages" but it still uses the path to the script as root directory, instead.

I know i can use try include for adjustments but it would be easier for me to use the same paths.

How can i set up the path for my python build system accordingly?

0 Likes

#2

You’ve got a few issues here; $USER is going to be the name of your actual user:

tmartin:dart:~> echo $USER
tmartin

If you want to access your home directory, you need to use something like /home/$USER or just $HOME instead (which is generally better, a user’s home directory can be anywhere. See for example root):

tmartin:dart:~> echo $HOME
/home/tmartin

Additionally, anything in shell_cmd, cmd or working_dir in a build system that includes a $ is treated as a variable and expands out, and anything that’s not a known variable is expanded out to be an empy string, so $HOME expands out to an empty string and your path would end up being /.config/sublime-text-3/packages as a result, which isn’t valid and so the working dir is not set (probably you see an error in the console when this build runs as a result).

To use something with a $ in it you need to enter it as \\$ instead; that gets loaded by the JSON parser as \$, Sublime sees it and converts it to $ without expanding anything, and it gets passed out to the command.

However all of that doesn’t really matter because it’s Sublime that needs to expand it if you’re going to use it in working_dir and it doesn’t expand environment variables (that’s a job for your shell), so the directory won’t be set anyway.

The only variables you can use in shell_cmd, cmd and working_dir that Sublime will expand are listed in the documentation on build systems; there’s one that expands out to the packages directory already. So what you want is this:

{
    "shell_cmd": "pwd",
    "working_dir": "$packages"
}
0 Likes