In John Siracusa’s excellent review of OS X Mavericks, he (originally) mentioned that the Terminal application is able to restore the current working directory of open shells across launches.
However, this section has subsequently disappeared from the online version,
perhaps for the reasons given below . Try looking here for a cached version of the original; scroll down to page/slide number 94. Sorry, John. Please purchase the full review on the iBooks store or the Amazon Kindle store to support John’s work.
Of course I was excited to try this out as, in the course of my work as a software developer, I often have several shell windows open in specific directories. So I tried it, and it didn’t work. It turns out the built-in support supplied by Apple assumes that you’re using the bash shell, but as an old-timer I’m stuck on tcsh instead:
Well, that’s no good, I thought. So I looked in the supporting code’s implementation (
/etc/bashrc), and figured out how to do the same thing in tcsh. Simply place the following in your
if ("$?TERM_PROGRAM") then
if ("$TERM_PROGRAM" == "Apple_Terminal") then
alias precmd 'printf "\033]7;%s\a" "file://$host$cwd:ags/ /%20/"'
This uses the appropriate escape sequence to send the URL of the current working directory to the terminal before each command; Terminal detects this information and uses it to update the state of the window (including a proxy icon in the window’s title bar for the corresponding folder). It turns out that the key is doing it using
precmd (tcsh’s equivalent of
PROMPT_COMMAND), and not sending the sequence in the prompt string itself as one might think.
I’ve notified John via Twitter, so perhaps he add restore this information back to his review. In any case, it’s documented here for future generations. Drop me a note below if you have any issues with it.