Search code examples
buildsublimetext3sublimetextsublime-build

Adding subcommand within Sublimetext custom build


In Sublimetext editor, we can specify custom build command using shell_cmd exec Target Options.

I want to add a subcommand within shell_cmd value. For Linux terminal commands, this can be done as outer-bin arg1 $(inner-command), where $(inner-command) provides the second argument for the outer-bin command.

I edit and run Tamarin models with Sublimetext. Some model files (e.g. LAK06-UK3.spthy) contain user-defined lemma (e.g. executable) and some implicit lemmas (e.g. Observational_equivalence). The default Tamarin command with --prove flag proves all user-defined and implicit lemmas. However, with the subcommand in the build system, I wish to pass only user-defined lemma. The build command including the subcommand for the LAK06-UK3.spthy could be:

tamarin-prover --diff LAK06-UK3.spthy $(python3 extract_lemma_cmd.py LAK06-UK3.spthy)

which translates to

tamarin-prover --diff LAK06-UK3.spthy --prove=executable

Any idea, how can I do this for Sublimetext custom build command?


Solution

  • You can use $() for command substitution, you just need to escape the $:

    {
        "shell_cmd": "tamarin-prover --diff $file_name \\$(python3 extract_lemma_cmd.py $file_name)",
        "working_dir": "$file_path"
    }
    

    Make sure you use a double backslash \\$ for the escape.

    Another solution is to use backticks:

    {
        "shell_cmd": "tamarin-prover --diff $file_name `python3 extract_lemma_cmd.py $file_name`",
        "working_dir": "$file_path"
    }
    

    Please note that these shell_cmds will only work as-is on Linux and Mac. For Windows, they need to be run using bash -c, as the default shell on Windows is cmd.exe.