Skip to content

Instantly share code, notes, and snippets.

@dgmike
Forked from karmi/run_selection_as_command.py
Created October 1, 2012 12:53
Show Gist options
  • Save dgmike/3811630 to your computer and use it in GitHub Desktop.
Save dgmike/3811630 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 RunSelectionAsBashCommand(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 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