Permalink
Browse files

added openwith option

  • Loading branch information...
1 parent 4324ac7 commit 34a3c0596b345b83e0a4bc56e20e5dc3ae572207 @noahcoad committed Feb 21, 2013
Showing with 26 additions and 11 deletions.
  1. +7 −2 README.md
  2. +2 −1 example.txt
  3. +1 −0 notes.txt
  4. +14 −7 open_url.py
  5. +2 −1 open_url.sublime-settings
View
@@ -26,8 +26,13 @@ Ways to run the command:
**Watch a little 1 min [video demo](http://www.screencast.com/t/AmuNuwqOfg).**
-## Configuration
-* Default Actions: You can set specific file extensions to be edit or run without being prompted with a menu. The default has been set for .sublime-project .txt and a few other files types. Open open_url.sublime-settings to change and add your own.
+## Options
+### Default Actions
+You can set specific file extensions to be edit or run without being prompted with a menu. The default has been set for .sublime-project .txt and a few other files types. Open open_url.sublime-settings to change and add your own.
+
+* If the action is 'edit' it will be opened for editing in Sublime
+* If the action is 'run' it will be executed by the OS
+* You can add an 'openwith': 'myprogram.exe' to the end of an 'endswith' line to specify a specific a program to open the file with. In this case the shell will execute the openwith program and the selection will be a parameter.
## Credits
Thanks goes to peterc for starting [a forum thread](http://www.sublimetext.com/forum/viewtopic.php?f=2&t=4243) about this topic and KatsuomiK for [his gist](https://gist.github.com/3542836) that was the start of this plugin.
View
@@ -8,4 +8,5 @@ http://www.google.com/reader/view/
google.com/reader/view/
C:\Temp\tmp.txt example.py
../Default/Preferences.sublime-settings
-c:\Program Files\Internet Explorer
+c:\Program Files\Internet Explorer
+C:\Noah\Projects\people\ChrisFritchie\ChrisFritchie.sublime-project
View
@@ -3,6 +3,7 @@ bugs
improvement ideas
backlog
+ add run with
Open multipe items with a return or carrage return like these:
http://google.com
gmail.com
View
@@ -2,14 +2,15 @@
# Hosted at http://github.com/noahcoad/open-url
import sublime, sublime_plugin
-import webbrowser, urllib, thread, re, os
+import webbrowser, urllib, thread, re, os, subprocess
sets_name = "open_url.sublime-settings"
config = sublime.load_settings(sets_name)
class OpenUrlCommand(sublime_plugin.TextCommand):
open_me = ""
+ open_with = None
def run(self, edit):
s = self.view.sel()[0]
@@ -46,7 +47,7 @@ def run(self, edit):
try:
relative_path = os.path.normpath(os.path.join(os.path.dirname(self.view.file_name()), url))
except TypeError:
- relative_path = url
+ relative_path = None
# debug info
print("URL : " + url)
@@ -59,13 +60,13 @@ def run(self, edit):
if os.path.isdir(url):
os.startfile(url)
- elif os.path.isdir(relative_path):
+ elif relative_path and os.path.isdir(relative_path):
os.startfile(relative_path)
elif os.path.exists(url):
self.choose_action(url)
- elif os.path.exists(relative_path):
+ elif relative_path and os.path.exists(relative_path):
self.choose_action(relative_path)
else:
@@ -87,6 +88,9 @@ def choose_action(self, file):
for ending in auto['endswith']:
if (file.endswith(ending)):
action = auto['action']
+ if ('openwith' in auto):
+ self.open_with = auto['openwith']
+ print(self.open_with)
break
if action == 'menu':
sublime.active_window().show_quick_panel(["Edit", "Run"], self.select_done)
@@ -96,15 +100,18 @@ def choose_action(self, file):
self.select_done(1)
# shell execution must be on another thread to keep Sublime from locking if it's a sublime file
- def run_me(self, file):
- os.system("\"" + file + "\"")
+ def run_me(self, file, open_with):
+ if open_with:
+ subprocess.call([open_with, file], shell = True)
+ else:
+ os.system("\"" + file + "\"")
# for files, either open the file for editing in sublime, or shell execute the file
def select_done(self, index):
if index == 0:
self.view.window().open_file(self.open_me)
elif index == 1:
- thread.start_new_thread(self.run_me, (self.open_me,))
+ thread.start_new_thread(self.run_me, (self.open_me, self.open_with))
# p.s. Yes, I'm using hard tabs for indentation. bite me
# set tabs to whatever level of indentation you like in your editor
@@ -2,6 +2,7 @@
"autoactions": [
{ "endswith": [".sublime-project"], "action": "run" },
{ "endswith": [".sln"], "action": "run" },
- { "endswith": [".txt"], "action": "edit" }
+ { "endswith": [".txt"], "action": "edit" },
+ { "endswith": [".exe"], "action": "run" }
]
}

0 comments on commit 34a3c05

Please sign in to comment.