2

One of my Macs is running Mac OS Mojave and so for parity with my Catalina machine I switched the shell to zsh. Not sure exactly when but at some point I noticed the current working directory was never being displayed either in the prompt itself or in the title of the tab.

I found I way to restore the title to the prompt by adding this to my ~/.zprofile file: PROMPT='%~ '. However, I have not been able to restore the directory name to the tab title:

Terminal window with tabs

This is quite frustrating when dealing with multiple tabs, as I do daily. It would seem to me that everything in the Terminal's settings is correct:

Terminal Preferences

Am I missing something or have I encountered a strange bug?

  • Open the Tab-tab in Terminal Prefs > Profile > [Profile name] (instead of the Window-tab) and check the radio buttons! – klanomath Dec 17 '19 at 23:41
  • I haven't tested this, but try copying the /etc/zshrc and /etc/zshrc_Apple_Terminal files from your Catalina system to the Mojave system (after backing up the original Mojave zshrc). – Gordon Davisson Dec 18 '19 at 7:39
  • @klanomath Tried this, the same boxes are checked!! – Ben Cheshire Dec 18 '19 at 9:08
  • @GordonDavisson I won't be able to try this until Friday but will give it a go – Ben Cheshire Dec 18 '19 at 9:08
  • I should note, changing back to bash fixes it entirely. Something's up with zsh – Ben Cheshire Dec 18 '19 at 9:46
1

Solution: Copy the zsh setup files (/etc/zshrc and /etc/zshrc_Apple_Terminal) from a Catalina system to the older system (preferably after backing up the original equivalent(s)).

I haven't tested this in Mojave, but I did in High Sierra, and it works fine there.

Explanation of the problem: Setting the Terminal window/tab title requires running some code (e.g. a shell function) to send the appropriate escape sequences, encoded version of the directory name, etc to the Terminal. In older versions of macOS, this was handled in bash by having /etc/bashrc run /etc/bashrc_Apple_Terminal, which defined a suitable function and set PROMPT_COMMAND to tell bash to run it each time it prompted for a new command. But since zsh wasn't the default shell, Apple didn't bother to create the equivalent setup scripts for zsh.

In Catalina, zsh is the default shell, so they wrote analogous setup steps and added them to /etc/zshrc and /etc/zshrc_Apple_Terminal. The mechanics are different (for example, zsh uses add-zsh-hook precmd instead of the PROMPT_COMMAND variable), but it does essentially the same thing. These files are not dependent on anything in Catalina; you can simply copy them to older systems, and they should work the same as they do in Catalina.

|improve this answer|||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .