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 {}" \;