sublime text 3 cmd 插件

2019-07-23 17:41  159人阅读  评论 (0)
Tags: sublime

安装方法

点击菜单 Preferences\Browse Packages...

创建一个文件夹 Cmd

创建如下三个文件

Side Bar.sublime-menu

[
  { "caption": "Cmd", "command": "cmd", "args": { "dirs": [], "files": [] } }
]

Context.sublime-menu

[
  { "caption": "Cmd", "command": "cmd", "args": { "dirs": [], "files": [] } }
]

cmd.py

import os, sublime_plugin
class CmdCommand(sublime_plugin.TextCommand):
  def run(self, edit, dirs = [], files = []):
    print(dirs, files, self.view.file_name())
    dir_name = dirs[0] if len(dirs) > 0 else os.path.dirname(files[0] if len(files) > 0 else self.view.file_name())
    driver, directory = os.path.splitdrive(dir_name)
    os.system(driver + " & " + "cd " + directory + " & start cmd")