Sublime Text 2 - 在当前或项目目录中打开CMD提示符(Windows) [英] Sublime Text 2 - Open CMD prompt at current or project directory (Windows)

查看:257
本文介绍了Sublime Text 2 - 在当前或项目目录中打开CMD提示符(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现以下Sublime命令非常有用,因为它在当前文件的位置打开一个explorer窗口:

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

我喜欢的是一个类似的命令,将打开一个cmd窗口。理想情况下,在根项目文件夹,但当前文件目录也会很好。



已阅读以下问题,但不能完全弄清楚如何使用sublime插件/命令:
BAT文件在当前打开CMD目录

解决方案


  1. 单击菜单 preference > 浏览器包 in Sublime Text 2。

  2. 创建文件夹 Cmd $ b>
  3. code> cmd 在第2步中创建的文件夹。



  import os,sublime_plugin 
class CmdCommand(sublime_plugin.TextCommand):
def run(self,edit):
file_name = self.view.file_name b $ b 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. 在步骤中创建的 cmd 文件夹中使用以下代码创建名为 Context.sublime-menu 的文件2。



  [
{command :cmd}
]




  1. 重新启动Sublime Text 2。

现在,您可以在右键单击上下文菜单中的当前目录中打开Cmd提示。 p>

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

解决方案

  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 2.

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

这篇关于Sublime Text 2 - 在当前或项目目录中打开CMD提示符(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆