Toggle Node Build Window On Sublime Text 2
Solution 1:
One approach would be to, in your build system, first kill the running node process & if that's not successful pass the current file to node. So your node.sublime-build might look like this:
{
"cmd": [ "killall node || node \"$file\"" ],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell": true
}
Sublime only allows one command which is passed multiple arguments, so something like "cmd": [ "killall node ||", "node", "$file"]
wasn't working, though I think it worked previously in Sublime 2. Thus the need to wrap $file
in escaped quotes, because otherwise the command will fail if the path to $file
has a space in it. Also, ||
is pivotal here, because killall
exits with a status of 1 (error) if there were no processes to kill, so the first time it will run node but the second time it won't.
Note that, since we're working in the shell here, this is platform-specific. I don't know how to do the equivalent of ||
on Windows, but you'd just need something like this:
{
"cmd": [ "killall node || node \"$file\"" ],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell": true"windows": {
"cmd": [ "insert whatever works here..." ]
}
}
One big limitation is that this kills all running node processes; that'd be annoying if you want to keep something running in the background. If someone knows how to target a specific node process in a single command, please add to my answer.
Secondly, you could wrap the cmd in a bash script, which would make it easier to do multiple things like kill a particular process. Then the cmd array would be [ "bash", "name-of-script.sh" ]
. Using lsof
it would be rather easy to get the particular node process that's running your current file. You could also use bash -c
as the command and then paste a whole script into the second element of the cmd array.
Hope that helps. I'm missing one piece of your requirement: ESC
will still be needed to close the build window. Not sure what else can be done there without writing a Sublime plug-in.
Solution 2:
Anyway, I fix it in windows like that, stupid? who care
{
"shell": true,
"windows": {
"cmd": "(TASKKILL /F /IM node.exe || 1)&& node \"$file\""
}
}
Solution 3:
I did it the same way but not checking for any file other than .js files
{
"cmd": [ "killall node || node \"$file\"" ],
"selector": "*.js",
"shell": true"windows": {
"cmd": "(TASKKILL /F /IM node.exe || 1)&& node \"$file\""
}
}
This will kill any running node and restart the file whose tab is open
Post a Comment for "Toggle Node Build Window On Sublime Text 2"