Home Download Buy Blog Forum Support

View in Multiple Browsers

View in Multiple Browsers

Postby GMB on Sun Oct 07, 2012 7:26 pm

This is a simple way to assign "view in browser" commands for a number of browsers.

Add the key bindings below 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.

Code: Select all
{ "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"} }


Code: Select all
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)


FWIW, also up on Github at https://gist.github.com/3795759
GMB
 
Posts: 19
Joined: Mon Aug 13, 2012 5:05 pm

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 31 guests