Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

For quite a while, I've been using the supplied answers for Resume Zsh-Terminal (OS X Lion) to set the proxy icon for while running under zsh, and so far, it's been working quite well. However, I recently noticed that running in zsh under screen, zsh can no longer update about the current working directory.

After hunting around, it appears that screen accepts different escape sequences (or something along those lines) in order to set its titles, and there seems to be some miscommunication between screen and xterm, but in all, I haven't been able to find a solution to fix this problem.

I've added the following line to my .screenrc file, but to no avail:

termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'

I've seen a lot of different 'solutions', but none of them specifically to support this - any help?

To clarify, as per Chris's comments below: previously, I used the following line to update Terminal:

printf '\e]7;%s\a' "${PWD// /%20}"

That doesn't work under screen, either because of how printf functions, or because of the escape sequences used.

share|improve this question
It does not have to do with differences between printf and echo. It has to do with the fact that you’re using a different escape sequence. Apparently screen doesn’t know to pass the ESC ] 7 ; ... BEL (set working directory) sequence on to the terminal, but it knows about codes 0 through 2 (set the window and tab titles). The answer to your question would involve figuring out how to get screen to pass code 7 (and 6) through to the terminal. – Chris Page Mar 17 '12 at 4:23
@ChrisPage Thanks for the help; seems like I found a way around that, simply using different escape sequences. However, would there be a way to do that - and seemingly, shouldn't the termcapinfo line posted up there be doing that? – Itai Ferber Mar 17 '12 at 5:17
As I mentioned in my comments to your answer, this workaround is only a partial solution and has drawbacks. A proper answer to your question involves figuring out how to get screen to pass the “set working directory” escape sequence on to Terminal. It is apparently ignoring this sequence instead of passing it on. I don’t know enough about screen to evaluate the termcapinfo line, but hopefully someone else does and will be able to provide an answer. – Chris Page Mar 17 '12 at 5:52
A quick look at the screen man page indicates your termcapinfo may be properly structured, but all it’s doing is setting the window title: ts is using “ESC ] 2”. If you want it to set the working directory, you’ll need to use “ESC ] 7” (and arrange to set the value to a “file:” scheme URL and percent-encode illegal characters). But I suspect you’ll need to deal with this some other way, because ts is specifically meant to display a status/title string for human consumption, not to communicate the working directory to the terminal. – Chris Page Mar 17 '12 at 5:59
After some additional investigation, I’m under the impression that screen simply ignores any control codes it doesn’t understand and doesn’t have a mechanism to tell it to pass unrecognized codes along to the terminal. Hopefully someone else will find a way to do this (or perhaps screen is in need of some work to provide this). – Chris Page Mar 17 '12 at 6:18
up vote 0 down vote accepted

Ended up solving my own problem. I added a zsh hook to chpwd with the following code:

# Update Terminal about the current working directory.
if [[ "$TERM_PROGRAM" = "Apple_Terminal" ]]; then
    update_terminal_pwd() {
        echo -n "<ESC>]0;${$(pwd -P)//\/Users\/itaiferber/~}/"

    autoload add-zsh-hook
    add-zsh-hook chpwd update_terminal_pwd

That updates the title of the terminal window to the current working directory (shows an abbreviated path instead of a full file path, while following symlinks), as well as a document proxy icon.

To clarify, this needs used with the line mentioned in the question in one's .screenrc - it doesn't work right out of the box.

Again, as per Chris's comments, I want to be clear: it would simply appear that this answer offers the correct escape sequences to trigger Terminal title updating. I assume that with this configuration, screen can now update Terminal's title correctly.

share|improve this answer
Note: As of Mac OS X 10.7 Lion, Terminal supports explicit escape sequences for setting the current working directory and “represented file” (which can be used to show the document being viewed/edited in emacs, vi or less, for example). It’s the same basic sequence as setting the title, but use 7 instead of 0 and set the value to a “file:” scheme URL with all the appropriate characters percent encoded. See /etc/bashrc for example. This is the recommended approach. – Chris Page Mar 17 '12 at 3:36
As a convenience, if you don’t explicitly set the working directory (or represented file), Terminal also examines the window/tab title for something that looks like a valid local path, but this uses heuristics, is error prone, can cause delays while it examines the file system looking for a match against substrings, can’t support names with non-ASCII characters and, finally, isn’t guaranteed to be supported in future versions of Terminal. It was mostly added to aid in discoverability of the proxy icon features for users who already put the working directory in the title. – Chris Page Mar 17 '12 at 3:38
Can you clarify something: How does this answer the question? Because the question implies that you already had the shell configured properly, but there was some interference from screen not passing the escape sequences on to Terminal. This answer seems to merely be about configuring the shell to set the window/tab titles. – Chris Page Mar 17 '12 at 3:40
Also, when Terminal detects the pathname in the title, it doesn’t use it to restore the working directory for Resume. – Chris Page Mar 17 '12 at 4:05
Please use the complete, supported solution from my answer: – Chris Page Mar 17 '12 at 4:06

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.