gnome-terminal: keep track of directory in new tab

There is a bug related to this issue

All you need to do is add the following line to your .bashrc or .zshrc:

. /etc/profile.d/vte.sh

At least on Arch, the script checks if you are running either bash or zsh and exits if you are not.


Might as well crosspost this hacky solution from superuser:

[This] saves the current folder in a file, after every command (Doesn't hurt too much IMO) and opens a new terminal in the saved current folder.

add the following to .zshrc [or .bashrc]

# emulate bash PROMPT_COMMAND (only for zsh)
precmd() { eval "$PROMPT_COMMAND" }
# open new terminal in same dir
PROMPT_COMMAND='pwd > "${HOME}/.cwd"'
[[ -f "${HOME}/.cwd" ]] && cd "$(< ${HOME}/.cwd)"

Note that this you will also put you in your last-used directory when opening a new window.