Created
August 15, 2016 13:22
-
-
Save Ation/6fc825a94a155a5167047514f95ff77d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#{ "keys": [ "ctrl+alt+v" ], "command": "open_in_browser" }, | |
import sublime, sublime_plugin | |
import webbrowser | |
import os.path | |
import sys | |
class OpenInBrowserCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
filePath = self.view.file_name() | |
fileToOpen = os.path.basename(filePath) | |
if self.view.is_dirty(): | |
print("File %s is dirty. Saving..." % (filePath,)) | |
self.view.window().run_command("save") | |
host = '127.0.0.1\\' | |
completeUrl = host+fileToOpen | |
pythonVersion = sys.version_info[0] | |
if pythonVersion < 3: | |
webbrowser.open_new_tab(completeUrl.encode(sys.getfilesystemencoding())) | |
else: | |
webbrowser.open_new_tab(completeUrl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment