Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 - Open CMD prompt at current or project directory (Windows)

I have found the following Sublime command to be really useful since it opens an explorer window at the location of the current file:

{ "keys": ["ctrl+alt+o"], "command": "open_dir", "args": {"dir": "$file_path", "file": "$file_name"} }, 

What I would love is a similar command that will open a cmd window instead. Ideally at the root project folder, but current file directory would also be fine.

Have read the following question, but can't quite figure out how to use this in a sublime plugin/command: BAT file to open CMD in current directory

like image 762
captainclam Avatar asked Aug 24 '12 04:08

captainclam


People also ask

How do I open a command prompt in Sublime Text?

In the Sublime editor, click on Preferences and select Key Bindings – User. If you want to open command line prompt by command (by ‘cmd’ for example), Add the following context data into Default (Windows).sublime-keymap file. :

How do I add a path to the Sublime Text installation directory?

For the current user, select Pathin the User variables for {username}section For all users, select Pathin the System variablessection In the Variable valueinput, add an entry with the Sublime Text installation directory. If there is an existing value, add a ;before the Sublime Text directory.

How to run a program in sublime editor?

That is all about and you have done. Verify: Now, just test it. Open any program file in the sublime editor and Right-click (context menu). You can see the Cmd menu in Context menu options. Click on it. The command prompt will be opened through which you can compile and run your program.

What is the latest version of Sublime Text for Linux?

Version: Dev4.03.23.13.0 Sublime Text includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITORfor unix tools, such as git and subversion. Setup Windows Mac Linux Usage Configuring as EDITOR Setup


1 Answers

  1. Click the menu preference > Browser Packages in Sublime Text 2.
  2. Create a folder Cmd in the directory opened in step 1.
  3. Create a python file named cmd.py with the following code in the Cmd 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) 
  1. Create a file named Context.sublime-menu with the following code in the Cmd folder created in step 2.
[      { "command": "cmd" } ] 
  1. Restart Sublime Text.

Now you can open the Cmd prompt at the current directory in the right-click context menu.

like image 62
TomCaps Avatar answered Oct 15 '22 10:10

TomCaps