[TxMt] filtering command with CocoaDialog

Lang Riley lang at langriley.com
Sun Jan 9 04:07:59 UTC 2005


Eric,
I don't know if I will use it, though I may, but just wanted to thank  
you for sharing this.  I use your comment/uncomment stuff all day every  
day : )

Lang
On Jan 8, 2005, at 5:09 PM, Eric Hsu wrote:

> hi folks,
>
> Another tip I thought I'd share.  I often have situations where I have  
> to discard all lines in a file that start with a number, or other  
> cleanup tasks like that.  Now, you can use TM's  Text>Filter Through  
> Command... and then use grep or grep -v. But I have a hard time  
> remembering grep's regexp format. It's already all I can do to  
> remember TM's and Perl's.
>
> So I wanted to write a command to pop up a GUI input field so I could  
> enter in a Perl regexp for lines to match with two buttons so I could  
> either Keep only the matching lines or Discard the matching lines.
>
> So what I did was toss together a quick script in Perl and use  
> CocoaDialog as a front-end.  To use this, you need to download  
> CocoaDialog from <http://cocoadialog.sourceforge.net/download.html>,  
> and put it in /Applications.  (If you don't like that place, change  
> the path in the script.)
>
> If you don't have a need for this script, you still might be able to  
> get some mileage out of CocoaDialog. It is a simple way to get GUI  
> onto any script that talks to the command-line. It has a number of  
> different window formats. Pashua is neat, but it requires use-ing a  
> module, and Platypus is more for creating drag-and-drop things.
>
> good luck, Eric
>
> ---
> TM Command.
>
> Before: nothing
> Command:
> my$CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog"; 
> my$rv=`$CD inputbox --title "Filter with Regexp" --no-newline \\  
> --informative-text "Filter lines matching this Perl regular  
> expression:" \\    --text "" \\    --button1 "Keep" --button2  
> "Discard" \\    --width  
> 500`;my($button_rv,$term)=split/\n/,$rv,2; 
> while(<STDIN>){if($button_rv==2){unless(/ 
> $term/){print;}}elsif($button_rv==1){if(/$term/){print;}}}
>
> Stdin: selected
> Stdout: replace selected
>
>
> -- 
> Eric Hsu, Assistant Professor of Mathematics
> San Francisco State University
> erichsu at math.sfsu.edu
> http://math.sfsu.edu/hsu
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>




More information about the textmate mailing list