I really like the open command on OS X, but I was too lazy to look for its Linux equivalent.
Actually, my solution probably took less time than sifting through a google search:
system(case ARGV[0]
when /\.pdf/
“epdfview”
when /\.html/
“firefox”
when /\.(rb)|(pl)|(pm)/
“vim”
end + ” #{ARGV[0]}”)
Anyone else have fun little hacks they want to share?


Hello, this script can be easily exploited:
ruby ./yourscript.rb 'file.html && echo "evil" > /tmp/testfile'.
You should use system(case ... , ARGV[0]) instead.
If you are using gnome you can use the command "gnome-open" instead.
kind regards
nax
@nax
granted, but in that case maybe I'd just type:
$ echo "evil" > /tmp/testfile
$ open file.html
I'd probably use File.extname so that things like file.tar.gz don't trip it up, but I like the idea. I'll probably go make my own for the next half hour instead of doing something more productive.
@pete,
Good idea. I mostly wrote it for when I'm typing it by hand, so I don't really care if it's robust, but it's interesting to see two holes already found.
Spoiling the fun: libfile-mimeinfo-perl comes with mimeopen. mimeopen can also open file based on magic (-M switch).
man gnome-open
It doesn't surprise me that gnome-open exists, but I'm an awesome user:
http://awesome.naquadah.org/
So let's just say that I feel something more minimal is better.
@hdh, thanks for letting me know about mimeopen.
For the record, the cross-distro, cross-desktop Linux equivalent is xdg-open.
for Linux, there's gnome-open and xdg-open (from the xdg-utils package in Debian)
It can be better to write the whole path of your programs, not just the names, like /usr/bin/vim instead of vim.
man 1 see
gnome-open? xdg-open? When will Linux distros give more thought to usability? "open" is obvious and easy to remember. "xdg-open" is an abomination.
Приветствую всех!
У меня такой вопрос,кто что интересное подскажет буду признателен.
Мы с друзьями собираемся поехать в круиз по просторам России и ближнего зарубежья месяца на два на своих машинах,но не как не можем согласовать маршрут,если у кого уже был опыт такого путешествия,может,что посоветуете.Девчонок с собой не берем,думаем,что во все городах России с этим не будет проблем,если у кого будут рекомендации и в вопросе отдыха с девушками тоже буду признателен.
С уважением Сеньчик
@brandon
On Linux `open' is already taken for another command: openvt. I usually alias open to gnome-open or something similar. Problem solved.
There's a shell, yanno. And it's *already running*.
@wtf.
And Ruby does a great job as a shell scripting language. I have all sorts of fun stuff in ~/bin.
Quanto viene pagato mediamente un analista-programmatore a milano?
Salve!
fra qualche mese dovrei andare a Londra; mi consigliate una carta prepagata da poter usare l?? con facilit???
Io ho gi?? unaw Postepay..ma dubito che funzioni!!!
_________________________________
chat