[sf-perl] perl on a mac

Michael Friedman friedman at highwire.stanford.edu
Sun Nov 23 14:29:35 PST 2008


TextMate? Easy.

This is basically from the "Shell Script" bundle's "Run Script"  
command, just without the header & footer.

Go into the Bundle Editor and create a new Bundle (or pick a Bundle  
you already work in). I find it easiest to keep my commands out of  
existing bundles so I can reload them from the svn repository as needed.

Create a Command inside that Bundle. Name it something like "Run and  
Show HTML" or whatever.

For the command choose:
Save: Current File
Input: None
Output: Show as HTML
Commands: paste in the following <<GO;

if [ ! -x "$TM_FILEPATH" ]; then

   res=$(iconv <<APPLESCRIPT -f utf-8 -t mac|osascript 2>/dev/null
   tell app "TextMate" to return button returned of ¬
     (display dialog "To run “${TM_FILENAME}” as a shell script it  
needs to be executable.\n\nWould you like to make it executable?" ¬
       buttons {"Cancel", "Make Executable"} ¬
       with icon 1 default button 2)
APPLESCRIPT)

   if [[ "$res" != "Make Executable" ]]; then echo  
'<script>window.close()</script>'; abort; exit; fi
   chmod a+x "$TM_FILEPATH"
fi

"$TM_FILEPATH" 2>&1

GO

Then select your script and choose that command from that bundle.  
It'll run the script, asking to make it executable first if needed,  
and show the output as HTML in TextMate's HTML viewer. This uses  
WebKit, so it'll look just like it would in Safari. Links work, titles  
work, etc.

The core of the command, though, is just exactly what we've all been  
discussing for the command line: run this file and show the output in  
a browser. TextMate just takes care of the intermediate tmp file for  
you.

You'll probably want to customize this to suit your needs -- make  
another command that runs selected text, make commands to ssh to the  
server and run things, etc. You can use any language in a TM command  
that you like, including Perl. I just used shell commands here because  
it already exists. See the TextMate help files for details.

-- Mike


On Nov 23, 2008, at 1:31 PM, Walt Sanders wrote:

> Thanks Kevin.  This makes it just a little bit neater.  Now if I  
> could somehow get my Coda or TextMate to run the programs like  
> Terminal does, I would be 100% operational.  Just can't see how to  
> make these clients similarly interpret the perl to produce and open  
> an .html file.  If anyone knows how to do that, I'm buying the beers!
>
>
>
>
>
> On Saturday, at , Kevin Frost wrote:
>
>> Why the semicolon?  You may have thrown an error.
>>
>> I would do it like this, if for some reason I really didn't want my  
>> CGI programs executable:
>>
>> phrun() {
>>   perl "$1" > "$1.$$.html" && open "$1.$$.html"
>> }
>>
>> But that's still frighteningly unsafe for my taste.  Try "phrun -v"  
>> for instance. (It won't break anything; just use the Finder to look  
>> at the file.)
>>
>> It's also worth noting that a lot of "standard" CGI programs will  
>> output an HTTP header, which may not look so good in your browser.   
>> Getting around that is probably just as much work as setting up a  
>> local web server.
>>
>> -- f.
>>
>> On Nov 22, 2008, at 6:04 PM, Randal L. Schwartz wrote:
>>
>>>>>>>> "yary" == yary  <not.com at gmail.com> writes:
>>>
>>> yary> Try this, to save yourself some typing
>>> yary> $ phrun() {
>>> yary>   perl $1 > temporary.html | open temporary.html
>>> yary>  }
>>> yary> $ phrun idpass.cgi
>>>
>>> Why the pipe?  You're not piping anything.  A semicolon would be  
>>> more
>>> appropriate.
>>>
>>> -- 
>>> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503  
>>> 777 0095
>>> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
>>> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
>>> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside  
>>> discussion
>>> _______________________________________________
>>> SanFrancisco-pm mailing list
>>> SanFrancisco-pm at pm.org
>>> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>>
>> _______________________________________________
>> SanFrancisco-pm mailing list
>> SanFrancisco-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm

---------------------------------------------------------------------
Michael Friedman                     HighWire Press
Phone: 650-725-1974                  Stanford University
FAX:   270-721-8034                  <friedman at highwire.stanford.edu>
---------------------------------------------------------------------




More information about the SanFrancisco-pm mailing list