Permalink
Browse files

Sublime shouldn't wait for cmd.exe on Windows (blocks the main thread)

Generalize the launch terminal command and move terminal cmd configuration into
the keybindings files.
  • Loading branch information...
1 parent fae52f1 commit 229ff7bde27c80bfb9693287dc1907c6f3c44777 @misfo committed Feb 8, 2012
@@ -1,4 +1,7 @@
[
{"keys": ["ctrl+shift+c"], "command": "shell_prompt"},
- {"keys": ["shift+ctrl+alt+c"], "command": "launch_terminal"}
+ {"keys": ["shift+ctrl+alt+c"], "command": "subprocess_in_cwd", "args": {
+ // untested. Patches welcome :)
+ "cmd": ["gnome-terminal", "--tab"]
+ } }
]
@@ -1,4 +1,17 @@
[
{"keys": ["super+shift+c"], "command": "shell_prompt"},
- {"keys": ["shift+super+alt+c"], "command": "launch_terminal"}
+ {"keys": ["shift+super+alt+c"], "command": "subprocess_in_cwd", "args": {
+ // This AppleScript requires the access for assistive
+ // devices to be turned on in the Universal Access system
+ // preferences. Using Cmd-T keystroke instead (which
+ // doesn't require the above setting) does not work if keys
+ // are still held down from the Sublime Text keybinding.
+ "cmd": "osascript -e 'tell application \"Terminal\"' -e 'activate' -e 'tell application \"System Events\" to click menu item \"Basic\" of ((process \"Terminal\")'\\''s (menu bar 1)'\\''s (menu bar item \"Shell\")'\\''s (menu \"Shell\")'\\''s (menu item \"New Tab\")'\\''s (menu \"New Tab\"))' -e \"do script with command \\\"cd '$PWD' && clear\\\" in window 1\" -e 'end tell'",
+
+ // Wait for AppleScript to return a successful exit code. This allows
+ // for showing any error message the script may cause. For instance, if
+ // the user doesn't have their "Access for assistive devices" setting
+ // enabled.
+ "wait": true
+ } }
]
@@ -1,4 +1,6 @@
[
{"keys": ["ctrl+shift+c"], "command": "shell_prompt"},
- {"keys": ["shift+ctrl+alt+c"], "command": "launch_terminal"}
+ {"keys": ["shift+ctrl+alt+c"], "command": "subprocess_in_cwd", "args": {
+ "cmd": ["cmd.exe"]
+ } }
]
View
@@ -40,12 +40,6 @@ override the following settings:
[options that are available to build systems](http://sublimetext.info/docs/en/reference/build_systems.html)
are available here, but `file_regex`, `line_regex`, `encoding`, `env`, and
`path` are the only options that make sense to use with this plugin.
- * `terminal_cmd`: The shell command used to launch a terminal. If you're
- sharing your setup between multiple machines
- [like me](https://github.com/misfo/Sublime-Packages), make sure to put this
- setting in an OS-specific settings file (e.g.
- `Packages/User/Shell Turtlestein (OSX).sublime-settings` for OS X) so that
- it won't be used on other OSes.
PAQ
@@ -1,4 +0,0 @@
-{
- // untested. Patches welcome :)
- "terminal_cmd": "gnome-terminal --tab &"
-}
@@ -1,8 +0,0 @@
-{
- // This AppleScript requires the access for assistive
- // devices to be turned on in the Universal Access system
- // preferences. Using Cmd-T keystroke instead (which
- // doesn't require the above setting) does not work if keys
- // are still held down from the Sublime Text keybinding.
- "terminal_cmd": "osascript -e 'tell application \"Terminal\"' -e 'activate' -e 'tell application \"System Events\" to click menu item \"Basic\" of ((process \"Terminal\")'\\''s (menu bar 1)'\\''s (menu bar item \"Shell\")'\\''s (menu \"Shell\")'\\''s (menu item \"New Tab\")'\\''s (menu \"New Tab\"))' -e \"do script with command \\\"cd '$PWD' && clear\\\" in window 1\" -e 'end tell'"
-}
@@ -1,5 +1,4 @@
{
- "terminal_cmd": "start",
"input_widget": {
"syntax": "Packages/Batch File/Batch File.tmLanguage"
}
View
@@ -57,20 +57,23 @@ def run(self):
for (setting, value) in settings().get('input_widget').iteritems():
view.settings().set(setting, value)
-class LaunchTerminalCommand(sublime_plugin.WindowCommand):
+class SubprocessInCwdCommand(sublime_plugin.WindowCommand):
"""
Launch a terminal using the window's working directory
"""
- def run(self):
+ def run(self, cmd = None, wait = False):
cwd = cwd_for_window(self.window)
- cmd = settings().get('terminal_cmd')
- proc = subprocess.Popen(cmd, cwd=cwd,
- shell=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- output, _ = proc.communicate()
- return_code = proc.poll()
- if return_code:
- sublime.error_message("The following command exited with status "
- + "code " + str(return_code) + ":\n" + cmd
- + "\n\nOutput:\n" + output)
+ shell = isinstance(cmd, basestring)
+ if wait:
+ proc = subprocess.Popen(cmd, cwd=cwd,
+ shell=shell,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ output, _ = proc.communicate()
+ return_code = proc.poll()
+ if return_code:
+ sublime.error_message("The following command exited with status "
+ + "code " + str(return_code) + ":\n" + cmd
+ + "\n\nOutput:\n" + output)
+ else:
+ subprocess.Popen(cmd, cwd=cwd, shell=shell)

0 comments on commit 229ff7b

Please sign in to comment.