Luis Campos
Luis Campos

Reputation: 11

Sublime Editor 2: Key-bindings to send command to terminal

I'm very new to Sublime and advanced text editors to be honest and any help/straightening up would be appreciated.

I'd like to set up a key-binding in Sublime Editor 2 that executes a command in Terminal inserting the current file name.

Specifically, I'd like to execute an Rscript that will render the markdown I am working on, i.e. Execute the following file in Terminal (replacing FILE with the filename Sublime is focused on).

Rscript -e "library(rmarkdown);render(*FILE*, "pdf_document")"

I've found a subprocess call that should send a command like this to Terminal.app, but I don't know how to integrate it with Sublime

subprocess.call(['osascript', '-e', 'tell app "Terminal" to do script "Rscript -e "library(rmarkdown);render(*FILE*, "pdf_document")" in window 1'])

Any help or advice would me much appreciated! Thank you!

Upvotes: 1

Views: 246

Answers (1)

MattDMo
MattDMo

Reputation: 102852

I'd highly recommend checking out the R-Box plugin from Package Control for working with R. Like many packages, most of the active development work is occurring on the Sublime Text 3 version, so unless there is a really compelling reason to stay with ST2 I strongly suggest you upgrade. There are quite a few reasons to upgrade, which I won't get into here, but suffice it to say that ST3 is fast, stable, and perfectly useable for anyone, and most of all for this particular situations, contains many behind-the-scenes enhancements allowing plugins to do more than ever before.

Upvotes: 1

Related Questions