Use Mac OS X's "environment.plist" Variables in Shell Environment

Mac OS X keeps its environment in ~/.MacOSX/environment. But if you want to access those variables from the shell, it's a bit cumbersome to parse this file manually. So here is a little shell loop to do that (tested in zsh and bash):

# Iterate over all keys returned by defaults
# Get key's name into "$i"
# Set environment variable with key name to value obtained via defaults
for i in `defaults read $HOME/.MacOSX/environment \
    | sed -nE 's/^    ([a-zA-Z0-9]+) = (.+");/\1/p'`; do
    eval export $i="`defaults read $HOME/.MacOSX/environment $i`"
done