Pipe into Firefox
Tue 17th July 2007, 10.54 pm
Prompted by a discussion earlier with Tim, I've written a little scriptlet that might be useful to others who read this blog.
Ever wanted to be able to pipe arbitrary stuff into Firefox? This Perl one-liner achieves precisely that, even cleaning up the temporary file when it's done.
#!/usr/bin/perl -00
use File::Temp;$f=File::Temp->new;print{$f}<>;system qw{firefox -remote},"openURL(file://$f, new-tab)"
I saved it in my ~/bin so it would be in my path.
Go on, try it out:
pipe_into_firefox </etc/motd
ls /tmp | pipe_into_firefox
curl http://owl.me.uk/ | pipe_into_firefox
Tagged as: perl firefox oneliner
Pete
on Wed 18th July 2007, 1.27 pm
Why do people feel the need to obfuscate perfectly readable Perl scripts by writing them all on one line? I feel Perl's reputation has suffered for this affectation.
Sure, you can write a one-liner, but if it sacrifices readability (and thus maintainability) why not split it into multiple lines?
Rich
on Wed 18th July 2007, 9.07 pm
Because it looks good in a blog post. The reality is that I'd written it properly but I didn't use strict or add any error checking and so on so it was just as bad in the end across many lines.
In the workplace I would never write one-liners for this sort of thing, and I would never approve of others doing it either. Someone has to maintain those scripts after the author is gone.
fordprefrect on Thu 30th August 2007, 1.30 pm
Very nice, but... What if firefox isn't running? I get "Error: No running window found" Should be easy to fix but I don't really know perl.




