Sublime Forum

How to set the path of an executable

#1

I have a command set up like this:

{
        "caption": "Terminus: Open Julia Nightly",
        "command": "terminus_open",
        "args"   : {
            "cmd": ["c:/Users/PKrysl/AppData/Local/Programs/Julia/Julia-1.4.0-DEV/bin/julia.exe"],
            "cwd": "${file_path:${folder}}",
            "title": "Julia REPL",
            "env": {"JULIA_NUM_THREADS":"2"},
        }
    }

Would it be possible to use a ~ in the path? Like this?

{
        "caption": "Terminus: Open Julia Nightly",
        "command": "terminus_open",
        "args"   : {
            "cmd": ["~/AppData/Local/Programs/Julia/Julia-1.4.0-DEV/bin/julia.exe"],
            "cwd": "${file_path:${folder}}",
            "title": "Julia REPL",
            "env": {"JULIA_NUM_THREADS":"2"},
        }
    }

Or refer to the home folder in some other way? (Environment variable?)

0 Likes

#2

The shell_cmd should do the trick. It resolves the environment variables in the command string.

    {
        "caption": "Terminus: Open Julia Nightly",
        "command": "terminus_open",
        "args"   : {
            "shell_cmd": ["%LOCALAPPDATA%/Programs/Julia/Julia-1.4.0-DEV/bin/julia.exe"],
            "cwd": "${file_path:${folder}}",
            "title": "Julia REPL",
            "env": {"JULIA_NUM_THREADS":"2"},
        }
    },
1 Like

#3

Excellent, that worked. Thanks!

0 Likes

#4

Alas, it stopped working: Shell_cmd stopped working. I have no idea why, I think I’m still on the same version of ST3.

0 Likes

#5

IIRC, terminus was changed to accept a string only as shell_cmd instead of a list of arguments.

So, the following should work.

    {
        "caption": "Terminus: Open Julia Nightly",
        "command": "terminus_open",
        "args"   : {
            "shell_cmd": "%LOCALAPPDATA%/Programs/Julia/Julia-1.4.0-DEV/bin/julia.exe",
            "cwd": "${file_path:${folder}}",
            "title": "Julia REPL",
            "env": {"JULIA_NUM_THREADS":"2"},
        }
    },
0 Likes

#6

pkrysl@ucsd.edu

0 Likes

#7

Would you have any idea how to properly escape a space in the path?

0 Likes

#8

In order to have spaces in a command argument, you need to wrap it in double quotes. However double quotes are special in JSON (they delimit the keys), so you need to escape each one so that JSON knows they’re not to be treated normally.

So that would look something like:

"shell_cmd": "\"Some string that has spaces in it\" -other -stuff"

This is why build systems that ship with Sublime use \"$file\", so that if the file that’s being passed is in a folder that contains spaces, the underlying command can find the file properly.

0 Likes

#9

Thank you. That’s what I tried before posting. It didn’t work.

'C:\Users\PKrysl\AppData\Local/Programs/Julia' is not recognized as an internal or external command,                                                                                            
operable program or batch file.                                                                 
process is terminated with return code 1.
0 Likes

#10

Perhaps it is something to do with running sublime text from a Git bash shell?
I noticed that this works in the shell
AppData/Local/Programs/Julia\ 1.5.0-DEV/bin/julia
but this setting does not produce the desired effect:

"shell_cmd": "\"%LOCALAPPDATA%/Programs/Julia\\ 1.5.0-DEV/bin/julia.exe\"",
0 Likes

#11

The magic incantation was:
"shell_cmd": "%LOCALAPPDATA%\\Programs\\\"Julia 1.5.0-DEV\"\\bin\\julia.exe",.
Why? No clue… :frowning:

0 Likes

#12

It’s because Windows uses backslashes to delineate? directories, while Linux and (probably Mac) use slashes. You have to escape the backslash with a backslash, hence the double backslash.
The backslash is a special character that must be escaped to work properly.

0 Likes

#13

As you say. But my confusion was about why "\"%LOCALAPPDATA%/Programs/Julia\\ 1.5.0-DEV/bin/julia.exe\"" was not successful, whereas "%LOCALAPPDATA%\\Programs\\\"Julia 1.5.0-DEV\"\\bin\\julia.exe" was.

0 Likes