Skip to content

Instantly share code, notes, and snippets.

@Ation
Created August 15, 2016 13:22
Show Gist options
  • Save Ation/6fc825a94a155a5167047514f95ff77d to your computer and use it in GitHub Desktop.
Save Ation/6fc825a94a155a5167047514f95ff77d to your computer and use it in GitHub Desktop.
#{ "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