Sublime Text 2 - Open CMD prompt at current or project directory (Windows)
- Click the menu
preference
>Browser Packages
in Sublime Text 2. - Create a folder
Cmd
in the directory opened in step 1. - Create a python file named
cmd.py
with the following code in theCmd
folder created in step 2.
import os, sublime_plugin
class CmdCommand(sublime_plugin.TextCommand):
def run(self, edit):
file_name=self.view.file_name()
path=file_name.split("\\")
current_driver=path[0]
path.pop()
current_directory="\\".join(path)
command= "cd "+current_directory+" & "+current_driver+" & start cmd"
os.system(command)
- Create a file named
Context.sublime-menu
with the following code in theCmd
folder created in step 2.
[
{ "command": "cmd" }
]
- Restart Sublime Text.
Now you can open the Cmd prompt at the current directory in the right-click context menu.
Just to expand on TomCaps answer, you can also open the command prompt at the root project folder (as was requested in the question), by changing step 3 to:
Create a python file named cmd.py with the following code in the cmd folder created in step 2.
import os, sublime, sublime_plugin class CmdCommand(sublime_plugin.TextCommand): def run(self, edit): file_name=sublime.active_window().project_file_name() path=file_name.split("\\") current_driver=path[0] path.pop() current_directory="\\".join(path) command= "cd "+current_directory+" & "+current_driver+" & start cmd" os.system(command)
The Shell Turtlestein package also has a command for this.
With that package installed, you can type CTRL+SHIFT+ALT+C
(or CMD+SHIFT+ALT+C on mac) to open cmd/terminal in the current file's folder.