Git and Rails : Switch your database.yml when changing branch

Posted by Antonin AMAND Wed, 09 Jul 2008 10:01:00 GMT

As a lot of people, I think, I have different database.yml file according to git branch I'm working on. I was constantly switching it manually until I discovered that git has more hooks that I thought.

I set up a post-checkout hooks script to automagically switch my database.yml when checking out a branch.

It is a simple script that recover the branch name a do a symlink.

if i checkout branch master it will look for a file named config/database.master.yml and create a symlink to config/database.yml

here it is :


#! /bin/sh
#
# .git/hooks/post-checkout

BRANCH=`git symbolic-ref HEAD 2> /dev/null | sed -e 's/^.*\///'`
GITPATH="`git rev-parse --git-dir 2>/dev/null`/.."

if [ "$BRANCH" == "" ]; then
        echo "no branch name. do nothing"
        exit 0
fi

if [ -f "$GITPATH/config/database.yml" ] && [ ! -L "$GITPATH/config/database.yml" ]; then
        echo "database.yml exists and not a symlink. do nothing."
        exit 0
fi

echo "look for $GITPATH/config/database.$BRANCH.yml"

if [ -f "$GITPATH/config/database.$BRANCH.yml" ]; then
        echo "switch database configuration file to config/database.$BRANCH.yml"
        rm -f "$GITPATH/config/database.yml";
        ln -s "$GITPATH/config/database.$BRANCH.yml" \
        "$GITPATH/config/database.yml"
fi
 

or on Pastie

Enable backspace when ssh into a debian machine with zsh 2

Posted by Antonin AMAND Tue, 30 Oct 2007 12:16:00 GMT

As many users of mac OS X, I’ve encountered some troubles with the backspace key when ssh into a debian machine.

Reading some posts on the web, I was thinking that the problem was about the shell or the tty. But in fact it was related to zsh.

The default zsh map on debian is not correct for mac users. The solution is to tell zsh how to bind keys.

echo "bindkey ^? backward-delete-char" >> ~/.zshrc
echo "bindkey ^[[3~ delete-char" >> ~/.zshrc

Use ctrl+v [key] to generate the ^... characters.

Mac OS X : properly change shell when using zsh from darwinports/macports

Posted by Antonin AMAND Wed, 06 Sep 2006 20:01:00 GMT

If like me you use a up to date zsh shell under Mac OS X installed via DarwinPorts (which change name to MacPorts) you may want to set it as your default shell.

To do this in a proper way (not by changing it in Terminal.app Preferences) you should proceed as following.

$ sudo vi /etc/shells
# add the following line : 
/opt/local/bin/zsh
$chsh
# and change /bin/bash to /opt/local/bin/zsh