Created
September 27, 2012 18:58
-
-
Save LeVM/3795759 to your computer and use it in GitHub Desktop.
Sublime Text 2 - View in multiple broswers
This file contains 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": ["alt+1"], "command": "open_browser", "args": {"keyPressed": "1"} }, | |
{ "keys": ["alt+2"], "command": "open_browser", "args": {"keyPressed": "2"} }, | |
{ "keys": ["alt+3"], "command": "open_browser", "args": {"keyPressed": "3"} }, | |
{ "keys": ["alt+4"], "command": "open_browser", "args": {"keyPressed": "4"} } |
This file contains 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
import sublime, sublime_plugin | |
import webbrowser | |
class OpenBrowserCommand(sublime_plugin.TextCommand): | |
def run(self,edit,keyPressed): | |
url = self.view.file_name() | |
if keyPressed == "1": | |
navegator = webbrowser.get("open -a /Applications/Safari.app %s") | |
if keyPressed == "2": | |
navegator = webbrowser.get("open -a /Applications/Google\ Chrome.app %s") | |
if keyPressed == "3": | |
navegator = webbrowser.get("open -a /Applications/Firefox.app %s") | |
if keyPressed == "4": | |
navegator = webbrowser.get("open -a /Applications/Opera.app %s") | |
navegator.open_new(url) |
This looks like it will only work with OS X. Is that right?
For people new to Sublime it might be worth noting that the file needs to have the ".py" suffix for this to work. The docs say the file name doesn't matter so I just used "OpenBrowser.py" to be more consistent. Thanks for the little plug-in. :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a simple way to assign "view in browser" commands for a number of browsers.
Add the key bindings above to your keymap (Sublime Text 2 > Preferences > Key Bindings - User), then create a "viewInBrowser" file and save it in Sublime Text 2 > Packages > User. Modify and or add/delete browsers as per your workflow.