Having switched over to ZSH, this is my revised solution to the problem using "profiles" triggered on directory changes. The nice thing about this solution is that it can be used for other settings.
Pop this into your zsh config:
#
# Thanks to: Michael Prokop.
# More documentation:
# http://git.grml.org/?p=grml-etc-core.git;f=etc/zsh/zshrc;hb=HEAD#l1120
#
CHPWD_PROFILE='default'
function chpwd_profiles() {
local -x profile
zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
if (( ${+functions[chpwd_profile_$profile]} )) ; then
chpwd_profile_${profile}
fi
CHPWD_PROFILE="${profile}"
return 0
}
chpwd_functions=( ${chpwd_functions} chpwd_profiles )
chpwd_profile_default # run DEFAULT profile automatically
And then elsewhere in your zsh git customizations:
zstyle ':chpwd:profiles:/home/user/work(|/|/*)' profile work
zstyle ':chpwd:profiles:/home/user/fun(|/|/*)' profile fun
# configuration for profile 'default':
chpwd_profile_default()
{
[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
print "chpwd(): Switching to profile: default"
export GIT_AUTHOR_EMAIL="default@example.com"
export GIT_COMMITTER_EMAIL="default@example.com"
}
# configuration for profile 'fun':
chpwd_profile_fun()
{
[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
print "chpwd(): Switching to profile: $profile"
export GIT_AUTHOR_EMAIL="fun@example.com"
export GIT_COMMITTER_EMAIL="fun@example.com"
}
# configuration for profile 'work':
chpwd_profile_work()
{
[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
print "chpwd(): Switching to profile: $profile"
export GIT_AUTHOR_EMAIL="work@example.com"
export GIT_COMMITTER_EMAIL="work@example.com"
}
answered 2011-12-27T13:18:42.037