Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 build via simple batch file

I've been playing a bit with ST2 and it seems like a pretty cute editor. Unfortunatelly, its documentation is horrible.

And I'm being nice. So here's my question.

I have five files in a directory, which I usually build via a .bat file with

ifort file1.f90 file2.f90 file3.f90 ...

how can I define and execute this line on windows cmd (taking account the enviromental variables like PATH) from ST2 via a shortcut and see the output? Is something like that even possible at this stage with ST2?

like image 565
Rook Avatar asked Apr 09 '12 02:04

Rook


1 Answers

This worked for me and works with paths and files with whitespaces.

I have fixed a bug which I've posted on the ST forum here and this here includes that fix.


Paste this into your Batch.sublime-build file. This will run cmd.exe and run the code in its native console. This will accept your inputs of the batch file.

{
  "file_patterns": ["*.bat", "*.cmd"],
  "selector": "source.batch",
  // This runs the batch file in the cmd window.
  "shell_cmd": "start \"${file_name}\" call \"${file}\""
}

Here's a build that can be saved as BatchStConsole.sublime-build This will run the code in Sublime Texts' console. This will not accept your inputs of the batch file. But still useful for debugging as it passes any arguments like the native CLI but just no interaction.

{
    "file_patterns": ["*.bat", "*.cmd"],
    "selector": "source.Batch",
    // This outputs to Sublime Texts' console
    "shell_cmd": "\"${file}\""
}

Also, in a new file ...\Data\Packages\User\Batch File.sublime-settings you can then place this code and save. This will build these filetypes when you have automatic build as your build detection.

{ "extensions": [ "bat", "cmd" ] }

Relevant help:

https://ss64.com/nt/start.html

https://docs.sublimetext.io/guide/usage/build-systems.html

https://www.sublimetext.com/docs/3/build_systems.html

like image 183
Ste Avatar answered Oct 11 '22 08:10

Ste