How to send the current working directory from bash to Terminal

bashterminal

I set up a very nice custom bash prompt in .bash_profile, but I noticed that I've now lost the ability for new tabs to open in the same directory, and the ability to see the current working directory's icon in the titlebar.

How can I get that back?

I've made some progress in the direction by adding "\e]2;\w\a" to $PS1, but that displays the full path in the titlebar, not just the name of the working directory. Any suggestions would be greatly appreciated.

Best Answer

Did you change PROMPT_COMMAND? The default PROMPT_COMMAND is defined in /etc/bashrc:

# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
        # Identify the directory using a "file:" scheme URL,
        # including the host name to disambiguate local vs.
        # remote connections. Percent-escape spaces.
        local SEARCH=' '
        local REPLACE='%20'
        local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
        printf '\e]7;%s\a' "$PWD_URL"
    }
    PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi