开发工具 sublime text 浏览器预览

Leron · November 27, 2012 · Last by ericguo replied at November 28, 2012 · 4440 hits

蛋疼的程序员

这个其实用 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" }
]
You need to Sign in before reply, if you don't have an account, please Sign up first.