Skip to content

Instantly share code, notes, and snippets.

@karmi
Created October 1, 2012 12:48
Show Gist options
  • Save karmi/3811569 to your computer and use it in GitHub Desktop.
Save karmi/3811569 to your computer and use it in GitHub Desktop.
Run selection as command in Sublime Text
import os, sublime, sublime_plugin
# Select some text and execute it through bash
#
class RunSelectionAsCommandCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if not region.empty():
# Get the selected text
command = self.view.substr(region)
print '========================================================================'
print command
print '------------------------------------------------------------------------'
print os.popen(command).read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment