开发工具 sublime text 浏览器预览

Leron · 2012年11月27日 · 最后由 ericguo 回复于 2012年11月28日 · 4440 次阅读

蛋疼的程序员

这个其实用 Package 有点多了,感觉自己写一个类似下面的OpenUrlInBrowser.py放到 User 目录下面也就差不多了。

import sublime, sublime_plugin, os, subprocess

class OpenUrlInBrowserCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            if not region.empty():
                s = self.view.substr(region)
                if s.find('.') == -1 and s.find('://') == -1 :
                    s = 'http://google.com/search?q='+s.replace(' ','+')
                command = "C:\\Program Files\\Mozilla Firefox\\firefox.exe " + s
                subprocess.Popen(command)

然后在 User 目录下新建:Context.sublime-menu,就可以在选中的上下文 url 中打开浏览器了。

[
    { "caption": "-", "id": "file" },
    { "command": "open_url_in_browser", "caption": "Open in Firefox" }
]
需要 登录 后方可回复, 如果你还没有账号请 注册新账号