+16

Filter through command equivalent

Colin Taylor 13 years ago updated by mc0e 11 years ago 4
Textmate blows but its ability to filter current doc through shell command and back in again is great.

I look for this feature in every editor I plan to use. It's a simple mechanism which expands the capability of the editor greatly. You can run grep, or quick sed, awk or perl one-liners over your selection. 


The implementation of this feature in TextMate is good (Text > Filter through command...). There is also a plugin which provides this functionality for jEdit.




+1
http://manual.macromates.com/en/shell_commands#executing_commands_filtering_text

That is the one command I miss from textmate very much, it satisfies the unix philosophy.

Sorting selections on arbitrary columns, transformations with sed/awk/cut/perl .

Why re-implement such things as plugins, when the functionality already exists in unix?

I suspect that this would be trivial to implement as a plugin, so it probably already is.

If not, I will probably implement it myself, but I wish it were a builtin function.

http://manual.macromates.com/en/shell_commands#executing_commands_filtering_text

That is the one command I miss from textmate very much, it satisfies the unix philosophy.

Sorting selections on arbitrary columns, transformations with sed/awk/cut/perl .

Why re-implement such things as plugins, when the functionality already exists?

I suspect that this would be trivial to implement as a plugin, so it probably already is.

If not, I will probably implement it myself, but I wish it were a builtin function.

EDIT: yep, one implementation here: https://gist.github.com/1251716 

The implementation in NEdit is awesome.  Shame that it's otherwise had so little love for so long.


You can set up reusable filters that do things like filter the current selection if there is one, else the whole window, and return results in place of the original, or in a new window.


Things I've used this for have included

 * passing html through tidy

 * pass current selection through `perl -wc` and return result in a new window.

 * pass current selection (or fall back on whole window) through ssh to a remote server, where it runs in a given directory and libraries, and the result comes back through ssh and into a new window.


Nedit also has two very useful options for ad-hoc stuff.

 * filter the current selection through a command line from a dialog (with history via arrow keys), and replace the original.

 * execute the current line (ie under the cursor) as a shell command, and insert the output just after that line.