OS X Mountain Lion terminal tab name + open a new tab in the same directory

Solution 1:

The default PROMPT_COMMAND behavior is defined in /etc/bashrc and adds the path to the working directory to the window title in a way that preserves the Same Working Directory functionality (as file:// URL), and even allows browsing to ancestor directories by Command-clicking the title bar.

If you additionally want to set the tab title to the base name of the working directory, you need to preserve the original PROMPT_COMMAND. In your user profile's shell initialization file of choice, use the following:

function set_tab_title {
  echo -n -e "\033]0;${PWD##*/}\007"
}

PROMPT_COMMAND="set_tab_title ; $PROMPT_COMMAND"