file search similar to TextMate’s CMD-T, in bash.
I’m a command line guy. I code Rails apps in vim. I’m happy. I am, however, slightly jealous of TextMate’s CMD-T feature, where you can open a file just by typing a part of the name.
Dusty pointed me to a vim tip for CMD-T like search in vim, but I don’t usually open files from within vim - I do it from the command line.
Here’s my hacked up way to get the same feature from within my normal bash shell. It requires dialog, which I installed with a sudo port install dialog.
add this code to your .bash_login (or equivalent)
function _vfind {
find -E . -type f -name "*$1*" ! -regex '.*/(\.git|\.svn|vendor|log).*' | sed 's/^\.\///' > /tmp/_$$_vfind_files
FOUND=`wc -l /tmp/_$$_vfind_files | awk '{ print $1 }'`
if [ "$FOUND" = "0" ]; then
echo 'no matching files...'
return
fi
cat /tmp/_$$_vfind_files | awk '{ print NR " " $0 }' | xargs dialog --menu 'Choose a file:' 0 0 0 2>/tmp/_$$_vfind_num
tput clear
if [ $? -eq 0 ]; then
FILENUM=`cat /tmp/_$$_vfind_num`
vi `awk "FNR == $FILENUM" /tmp/_$$_vfind_files`
fi
rm -f /tmp/_$$_vfind_files /tmp/_$$_vfind_num
}
alias f=_vfind
Close and re-open your terminal, or simply source ~/.bash_login, and try it out:
# cd my_rails_app # f helper
And here’s what you get:

Arrow around, hit enter to open a file, or escape to cancel. We’ll see if I stick with this in my daily workflow ;)