Sublime Forum

ST2: keybinds for command line functions

#1

I’ve just started looking at SublimeText2, but I can’t work out how to execute command line commands from a key bind. In SublimeText, I simply have this as my keybind

What would the equivalent be in ST2?

0 Likes

#2

I am also interested in figuring out how to solve this.

So far I have the key binding:

{ "keys": "ctrl+shift+1"], "command": "exec", "args": { "cmd": "C:\\Program Files\\TortoiseHg\\thg.bat", "commit", "$File"]} }

The bat-file is just a test script which prints out the arguments that is parsed onto it, but unfortunately $File doesn’t work.
I was hoping that the variables available with “Build Systems” (sublimetext.com/docs/build) also worked here.

Is the above possible with a regular key binding or do we need to make a small plugin which calls the script?

Thanks in advance

0 Likes

#3

I have found out how to execute external programs with Build System, but then I can’t figure out how to make a key binding to build a specific system.

In my case I want two shurtcuts - one to call “php.exe -l $file” for syntax check and one to call “thg.exe commit $file”.
Both of these commands works fine when selected in “Build System” and then pressing i.e. F7.

What I am trying to get done is to make a key binding to each of them, so I don’t have to first select which build system I want to use.

@ifni: Sorry if I am “hijacking” your thread, but I believe we seek exactly the same, so instead of starting a new thread I found it better to continue with this one.

0 Likes

#4

Finally nailed it… Here is what I have done:

Create two new plugins:
MercurialCommit.py

[code]import sublime, sublime_plugin

class MercurialCommitCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command(‘exec’, {‘cmd’: “c:\Program Files\TortoiseHg\thg.exe”, “commit”, self.view.file_name()]})
[/code]
PhpSyntaxCheck.py

[code]import sublime, sublime_plugin

class PhpSyntaxCheckCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command(‘exec’, {‘cmd’: “c:\files\php\php.exe”, “-l”, self.view.file_name()]})
[/code]
Bind the commands to a shortcut:
Preferences -> Key Bindings - User

{ "keys": "ctrl+shift+0"], "command": "php_syntax_check" }, { "keys": "ctrl+shift+1"], "command": "mercurial_commit" } ]
That works like a charm for me :smile:
(I’m not quite sure if you must restart Sublime Text in order to make it work)

0 Likes

#5

Where are php_syntax_check and mercurial_commit defined?

0 Likes

#6

Nevermind, I find the info here: sublimetext.info/docs/en/extensi … ugins.html

0 Likes

#7

There is a plugin that allows multiple tasks per build file called Multi Task Build; it is available through Package Control.

0 Likes