Sublime Forum

Not possible to expand path vars in exec command?

#1

I’m a little confused by something in ST3, and I’m not sure if the (unofficial) docs are wrong or I’m just
having a problem with the context that it’s talking about or what.

I"m trying to set up a key shortcut that will invoke an application that’s part of the project that I’m working on with the current file as an argument. I found this post from three years ago where someone was trying something similar but it seemed at the time that there was no recourse but to create a plugin to do it, which seems wrong somehow.

My key binding attempt is:

{
    "keys": ["ctrl+shift+alt+l"],
    "command": "exec",
    "args":
    {
        "cmd": ["$project_dir/Bin/dmlua", "$file"],
        "working_dir": "$file_path",
        "shell": true
    },
    "context":
    [
        { "key": "setting.datamill", "operator": "equal", "operand": true },
        { "key": "selector", "operator": "equal", "operand": "source.lua" }
    ]
}

However when invoked, I get an error:

FileNotFoundError: [Errno 2] No such file or directory: '$file_path'

Naturally, if I remove the working_dir, then it can’t find the executable, and if I put the executable in
the path, it can’t file $file.

Is this really something that’s not possible without having to resort to using a plugin? The unofficial documentation page on commands says:

The same variables available to build systems are expanded in arguments to commands. See Build System Variables for more information.

So it seems like this should actually work, but it doesn’t. Am I just misunderstanding here? Do I really have
to go the plugin route for this? I’m not averse to that, just want to clarify that I’m either the docs are wrong or (more likely) I’m not understanding what they’re telling me.

1 Like

Concatenating String Arguments in Key Bindings
#2

I actually strongly believe that not to be true, but I only read that part a few days ago myself. I added it to our todo however (I’m the co-author, if you didn’t know).

These variables should only be expanded in build systems and only in specific keys too.

1 Like

#3

Thank you for the clarification! I didn’t know you were co-author, but I’ll add another thank you for your work there because it’s really quite helpful.

In order to get up and running I whipped up some simple code that expands the variables for me, so all’s well that ends well. I assume there are probably some plugins already available that do the same thing but I didn’t investigate that too heavily because it seemed like it should work.

0 Likes