Im using zsh and it seems that a new tab should open in the same dir as the previous. However, that is not happening.

Do I have to add anything to the .zshrc?

  • 2
    What is a "new tab" and what does it have to do with zsh? – sarnold Dec 29 '11 at 5:04

Nothing to do with zsh.

Konsole and gnome-terminal do that: opening a new tab puts you in the same directory. (Once upon a time, opening a new tab in gnome-terminal while reading a man page put you in /usr/share/man, maybe it has been fixed)


You are probably using the "tabs" in a terminal emulator like gnome-terminal? Understand that a new tab is nearly indistinguishable from a new terminal window. It runs a new instance of the shell which executes its start up files. The startup files do not know about any other shell instances, let alone what gnome-terminal they belong to or which current working directory that shell might be in. Another issue: with several open shells in different directories, which directory should the new shell start in?

That said, you could make each cd save the target directory in say ~/.cd and change there in the startup file. Left as an exercise to the reader :-)

PS: Be sure to save the absolute path of the target directory, not some relative arg to cd.

  • This remembers last directory the user changed into, but not the directory that was open in the last terminal. For example, I could change into a directory in some terminal A, close it and some time later try to open a new terminal X while looking at terminal B. As as result I'll get the directory from the closed terminal A rather than from terminal B. – Sergiy Belozorov Apr 13 '18 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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