Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sligodave/2586767 to your computer and use it in GitHub Desktop.

Select an option

Save sligodave/2586767 to your computer and use it in GitHub Desktop.

Revisions

  1. sligodave revised this gist May 3, 2012. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions filter_through_command.py
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,23 @@
    # saved from: http://pastie.org/private/bclbdgxzbkb1gs2jfqzehg

    import sublime
    import sublimeplugin
    import sublime_plugin
    import subprocess

    class RunExternalCommand(sublimeplugin.TextCommand):

    class RunExternalCommand(sublime_plugin.TextCommand):
    """
    Runs an external command with the selected text,
    which will then be replaced by the command output.
    """

    def run(self, view, args):
    if view.sel()[0].empty():
    def run(self, edit, args):
    if self.view.sel()[0].empty():
    # nothing selected: process the entire file
    region = sublime.Region(0L, view.size())
    region = sublime.Region(0L, self.view.size())
    else:
    # process only selected region
    region = view.line(view.sel()[0])
    region = self.view.line(self.view.sel()[0])

    p = subprocess.Popen(
    args,
    @@ -26,9 +27,8 @@ def run(self, view, args):
    stderr=subprocess.PIPE,
    stdin=subprocess.PIPE)

    output, error = p.communicate(view.substr(region).encode('utf-8'))

    output, error = p.communicate(self.view.substr(region).encode('utf-8'))
    if error:
    sublime.errorMessage(error.decode('utf-8'))
    else:
    view.replace(region, output.decode('utf-8'))
    self.view.replace(edit, region, output.decode('utf-8'))
  2. @jefftriplett jefftriplett revised this gist Sep 29, 2011. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions filter_through_command.py
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,15 @@
    # saved from: http://pastie.org/private/bclbdgxzbkb1gs2jfqzehg

    import sublime, sublimeplugin
    import sublime
    import sublimeplugin
    import subprocess

    class RunExternalCommand(sublimeplugin.TextCommand):
    """
    Runs an external command with the selected text,
    which will then be replaced by the command output.
    """

    def run(self, view, args):
    if view.sel()[0].empty():
    # nothing selected: process the entire file
    @@ -19,11 +20,11 @@ def run(self, view, args):

    p = subprocess.Popen(
    args,
    shell = True,
    bufsize = -1,
    stdout = subprocess.PIPE,
    stderr = subprocess.PIPE,
    stdin = subprocess.PIPE)
    shell=True,
    bufsize=-1,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    stdin=subprocess.PIPE)

    output, error = p.communicate(view.substr(region).encode('utf-8'))

  3. @jefftriplett jefftriplett revised this gist Sep 29, 2011. 1 changed file with 24 additions and 24 deletions.
    48 changes: 24 additions & 24 deletions filter_through_command.py
    Original file line number Diff line number Diff line change
    @@ -4,30 +4,30 @@
    import subprocess

    class RunExternalCommand(sublimeplugin.TextCommand):
    """
    Runs an external command with the selected text,
    which will then be replaced by the command output.
    """
    def run(self, view, args):
    if view.sel()[0].empty():
    # nothing selected: process the entire file
    region = sublime.Region(0L, view.size())
    else:
    # process only selected region
    region = view.line(view.sel()[0])
    """
    Runs an external command with the selected text,
    which will then be replaced by the command output.
    """
    def run(self, view, args):
    if view.sel()[0].empty():
    # nothing selected: process the entire file
    region = sublime.Region(0L, view.size())
    else:
    # process only selected region
    region = view.line(view.sel()[0])

    p = subprocess.Popen(
    args,
    shell = True,
    bufsize = -1,
    stdout = subprocess.PIPE,
    stderr = subprocess.PIPE,
    stdin = subprocess.PIPE)
    p = subprocess.Popen(
    args,
    shell = True,
    bufsize = -1,
    stdout = subprocess.PIPE,
    stderr = subprocess.PIPE,
    stdin = subprocess.PIPE)

    output, error = p.communicate(view.substr(region).encode('utf-8'))
    output, error = p.communicate(view.substr(region).encode('utf-8'))

    if error:
    sublime.errorMessage(error.decode('utf-8'))
    else:
    view.replace(region, output.decode('utf-8'))
    if error:
    sublime.errorMessage(error.decode('utf-8'))
    else:
    view.replace(region, output.decode('utf-8'))
  4. @jefftriplett jefftriplett created this gist Sep 29, 2011.
    33 changes: 33 additions & 0 deletions filter_through_command.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # saved from: http://pastie.org/private/bclbdgxzbkb1gs2jfqzehg

    import sublime, sublimeplugin
    import subprocess

    class RunExternalCommand(sublimeplugin.TextCommand):
    """
    Runs an external command with the selected text,
    which will then be replaced by the command output.
    """

    def run(self, view, args):
    if view.sel()[0].empty():
    # nothing selected: process the entire file
    region = sublime.Region(0L, view.size())
    else:
    # process only selected region
    region = view.line(view.sel()[0])

    p = subprocess.Popen(
    args,
    shell = True,
    bufsize = -1,
    stdout = subprocess.PIPE,
    stderr = subprocess.PIPE,
    stdin = subprocess.PIPE)

    output, error = p.communicate(view.substr(region).encode('utf-8'))

    if error:
    sublime.errorMessage(error.decode('utf-8'))
    else:
    view.replace(region, output.decode('utf-8'))