Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like the title bar of Terminal to always show the directory I'm in. I don't want it shown in the prompt. I found some magic trick code online, and have this in my .tcshrc:

set prompt = "%B%m:%n %?====>%b "
alias cwdcmd 'echo -ne "\033]0;$cwd\007"'

It sort of works except for two things: 1) the cwd isn't shown in the title bar, and 2) the cwd along with some gibberish is printed at the command line. I figured maybe the quoting wasn't right, or some other syntax issue, but experimenting didn't lead to improvement.

For reasons unspecified, I must use tcsh not bash. The latter, I can get working fine.

share|improve this question
What escape sequences do you use with bash? The ESC ] 0 is for xterm, which I do not believe supports. – Thorbjørn Ravn Andersen Aug 10 '11 at 21:44
Yes, Terminal does support the Operating System Command (OSC) escape sequence (ESC ] Ps; Pt BEL) for setting the window/tab title. In Lion, it also now lets you set the tab title independently of the window title. – Chris Page Aug 11 '11 at 7:00
up vote 1 down vote accepted

This is what I have in my .cshrc

alias cwdcmd 'printf "\033]1;%s\007\033]2;%s\007" "$cwd:t" "$HOST echo $cwd | sed s-$HOME-~-" '

It does some additional stuff for iTerm, which I use instead of Termial, but seems to work fine there as well.

share|improve this answer
I suspect the "echo" and "sed" aren't supposed to show literally, but they do. No matter; if I chop them out I still get what I want to show. It works! – DarenW Aug 10 '11 at 23:35

This is the prompt I use in tcsh. It sets the window title to the full path (which as Chris Page answered, gains extra functionality in Lion). The prompt itself is essentially [$HOST:$PWD] $USER% using tcsh % syntax.

set prompt = '%{\e]2;%~\a%}%S[%m:%c3] %n%#%s '
share|improve this answer

As of Mac OS X Lion 10.7, Terminal now supports displaying the working directory using the standard window "proxy" icon. This is enabled by default for bash (the default shell). See /etc/bashrc for the relevant code.

This enables several behaviors, such as the ability to create a new terminal in the same directory (by default, New Tab will do so, and you can enable it when creating a new window), and restoring the working directory when quitting/restarting Terminal (for Resume). It also enables restoring working directories when opening Window Groups.

As a convenience, if you have your shell configured to put the working directory path in the window (or tab) title, Terminal will check whether the title contains a valid local path and provide some of the same behaviors automatically (although it won't restore the working directory for Resume).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.