ZSH DIRSTACK Script from Arch Wiki FIX for File Manager

geschrieben am Dienstag, 1. Mai 2018 um 13:26 Uhr.

Hello there,

if you find this post, you have a problem with ZSH and your term emulator. In my case, it was a problem with zsh and rxvt-unicode. You cannot open a specified directory like urxvt -cd /, so zsh ignores the given path from -cd switch.

This article is for you, if you use the following code from wiki.archlinux.org in your .zshrc:

1
2
3
4
5
6
7
8
DIRSTACKFILE="$HOME/.cache/zsh/dirs"
if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then
  dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
  [[ -d $dirstack[1] ]] && cd $dirstack[1]
fi
chpwd() {
  print -l $PWD ${(u)dirstack} >$DIRSTACKFILE
}

Comment out the highlighted line (line 4), because it overrides the -cd switch behaviour and change the current directory automatically to your last visited directoy. It is a nice tweak, but destroys the functionality of a file manager like spacefm to open a terminal in the current working directory (e.g. in spacefm: press f4). To open the previous directory, you can use cd -1 manually to enter the folder.

So you only have to comment out the previous line of code to get a working zsh installation.