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, 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@math.sfsu.edu http://math.sfsu.edu/hsu ______________________________________________________________________ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 9 Jan 2005, at 01:09, Eric Hsu wrote:
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.
Eric,
Thank you VERY MUCH for sharing this with us!!! CocoaDialog is really cool and is useful in so many areas, even outside of TM. It's kind of the answer to one of the problems I've been wrestling with in the past two weeks: "how to create an interactive TM command ?".
Allan,
Is there any chance that something like this can be incorporated into TM sort of like Web Preview is, with a Menu option and a Shell Variable option like $TM_STDINPUTBOX or something like it to obtain a standard input box ??? Just wondering : ) (as if you don't have enough on your plate already)
Kind regards,
Mats
On Jan 9, 2005, at 14:52, Mats Persson wrote:
[ CocoaDialog ]
Is there any chance that something like this can be incorporated into TM [...]
Yes, when I add apple script support (1.2/1.3) it will be possible to have TextMate do dialogs and such.