Bob Zoller
script/runner script that doesn’t require an absolute path
the output from Rails’ script/runner -h says you can create custom scripts with a fancy shebang line:
You can also use runner as a shebang line for your scripts like this:
-------------------------------------------------------------
#!/usr/bin/env /Users/bob/Projects/glowworm/script/runner
Product.find(:all).each { |p| p.price *= 2 ; p.save! }
-------------------------------------------------------------
but I hate the idea of hardcoding a path like that. Here’s a workaround: open up your new script, something like script/my_custom_script and fill it like so
#!/usr/bin/env ruby
unless $0 =~ /runner/
system("#{File.dirname(__FILE__)}/runner", __FILE__)
exit 0
end
puts 'your code goes here'
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 ;)
shared git repo (using ssh transport)
As a quick followup to my last post, here’s the steps I took to make my remote git repo usable by a group of developers, not just me:
/etc/group
After you’ve added accounts for everyone, make a group and add everyone to it. This line should look something like:
coders:x:114:bob,docyes,phillip
git repo-config
After creating the remote repo (git —bare init), we need to set the core.sharedRepository variable to “group” - this tells git to create directories and files with group-write permissions.
git repo-config core.sharedRepository group
fix permissions
Now that git will do the right thing, we need to fix the permissions on the existing files and directories.
sudo chgrp -R coders .
sudo chmod -R g+ws .
