Home Download Buy Blog Forum Support

ST2: keybinds for command line functions

ST2: keybinds for command line functions

Postby ifni on Wed Aug 31, 2011 1:14 pm

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

<binding key="ctrl+f7" command='exec "^(...*?):([0-9]*):?([0-9]*)" p4 edit \"$File\"'/>

What would the equivalent be in ST2?
ifni
 
Posts: 15
Joined: Thu Jan 21, 2010 11:40 am

Re: ST2: keybinds for command line functions

Postby janpolsen on Thu Sep 08, 2011 6:27 am

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

So far I have the key binding:
Code: Select all
{ "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" (http://www.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
Best regards,
Jan
janpolsen
 
Posts: 4
Joined: Thu Sep 08, 2011 5:43 am
Location: Denmark

Re: ST2: keybinds for command line functions

Postby janpolsen on Thu Sep 08, 2011 7:07 am

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.
Best regards,
Jan
janpolsen
 
Posts: 4
Joined: Thu Sep 08, 2011 5:43 am
Location: Denmark

Re: ST2: keybinds for command line functions

Postby janpolsen on Thu Sep 08, 2011 12:38 pm

Finally nailed it... Here is what I have done:

Create two new plugins:
MercurialCommit.py
Code: Select all
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()]})

PhpSyntaxCheck.py
Code: Select all
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()]})

Bind the commands to a shortcut:
Preferences -> Key Bindings - User
Code: Select all
[
{ "keys": ["ctrl+shift+0"], "command": "php_syntax_check" },
{ "keys": ["ctrl+shift+1"], "command": "mercurial_commit" }
]

That works like a charm for me :)
(I'm not quite sure if you must restart Sublime Text in order to make it work)
Best regards,
Jan
janpolsen
 
Posts: 4
Joined: Thu Sep 08, 2011 5:43 am
Location: Denmark

Re: ST2: keybinds for command line functions

Postby ifni on Wed Sep 28, 2011 12:06 pm

Where are php_syntax_check and mercurial_commit defined?
ifni
 
Posts: 15
Joined: Thu Jan 21, 2010 11:40 am

Re: ST2: keybinds for command line functions

Postby ifni on Wed Sep 28, 2011 12:49 pm

ifni wrote:Where are php_syntax_check and mercurial_commit defined?


Nevermind, I find the info here: http://sublimetext.info/docs/en/extensi ... ugins.html
ifni
 
Posts: 15
Joined: Thu Jan 21, 2010 11:40 am

Re: ST2: keybinds for command line functions

Postby quodlibet on Sun Mar 11, 2012 6:39 pm

There is a plugin that allows multiple tasks per build file called Multi Task Build; it is available through Package Control.
quodlibet
 
Posts: 544
Joined: Sat Jun 18, 2011 5:53 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 19 guests