Mac Terminal 'cd' to a folder alias

Solution 1:

Mac OS aliases are more similar to Windows shortcuts than to Unix symlinks; you can double-click them but you cannot cd into them.

This article explains how to make cd follow OS X aliases:

This is a two-part process requiring a little familiarity with gcc and bash, but I’ll try to make it as simple as possible. Firstly, you need this file: getTrueName.c. This file was created by Thos Davis and is licensed under the GPLv2. Save it anywhere, then compile it with the following command:

gcc -o getTrueName -framework Carbon getTrueName.c

This will create the ‘getTrueName’ executable in the same directory as the source. You can add it to your PATH, or just copy it directly to /usr/bin so it’s easy to access.

Interestingly, when Terminal opens a new shell, .bashrc is not executed as you might expect. Instead, under the login shell, .bash_profile is executed. So, add the following to .bash_profile in your Home directory. You might need to create it first; it isn’t there by default.

cd() {
  if [[ -f "$1" || -L "$1" ]]; then
    path=$(getTrueName "$1")
    builtin cd "$path"
  else
    builtin cd "$@"
  fi
}

[edited the function a bit –grawity]