Atom Feed SITE FEED   ADD TO GOOGLE READER

Stupid Bash Tricks: Open a file

Frequently I'm working from the command line in my Mac OS X box, and I want to open a file in my editor. With my file-type associations set, this is as easy as
$ open ./source/ca/odell/centricclient/Contact.java
The only problem is that I'm a lazy programmer and that's a lot to type. Plus I need to get the directories right.

With my new 1-line fopen script, I can open the file easier:
$ fopen Contact.java
This works as long as Contact.java is in a subdirectory of the current working directory. It will open all files that contain "Contact.java" in their name. If I wanted to open all of my decorator files, I might call
$ fopen Decorator
This would open TableModelDecorator.java, ButtonDecorator.java, and even Decorator Invoice.pdf.

Here's the script:
#!/bin/bash
find . -name "*$1*" -exec bash -c "echo {} && open {}" \;
Simple and beautiful :) Thanks for tip.
Nice tip. I'd recommend the use of -print0 for more safety regarding quoting:

#!/bin/bash
find . -iname "*$1*" -print0 | xargs -0i bash -c "echo {} && open {}"