agkozak/zsh-z

pushdignoredups is not respected - after using 'z' duplicates appear on the dirstack

catweazle9 opened this issue · 17 comments

I have the following options enabled (among others): autopushd pushdminus pushdsilent pushdtohome pushdignoredups

After using 'z', every time I visit a particular directory I see it duplicated on the dir stack (as shown by dirs -v). I seem to have worked around the problem by modifying zsh-z.plugin.zsh to add this line just after the zparseopts line:
setopt pushdignoredups

I don't know exactly why the option is not being restored when the 'z' function terminates. I would have thought the LOCAL_OPTIONS should have taken care of it? Maybe the issue is that emulate -L zsh sets various default zsh options and pushdignoredups is not enabled by default, so when the cd command runs, the dup gets added to the dir stack?

Anyway I'm using ZSH_VERSION 5.5.1 under Cygwin on Windows. I don't use any of the 'package' systems such as oh-my-zsh or the like.

Thanks for giving so many details! I'll try to take a look into this later today.

I’m trying what you described, with

setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups

both with my default setup, and after starting zsh in plain vanilla mode (zsh -f) and then sourcing ZSH-z, and I’m not seeing what you describe. I don’t see duplicates when I run dirs -v, and pushdignoredups is never disabled.

Could you post your whole .zshrc, or provide a link to it? I’m sure that will allow me to see exactly what is going on. Thanks!

Never mind -- I shouldn't have responded so quickly. I can see what you mean, and I suspect that your analysis is quite correct. Let me see what I can do. It is possible that I can do something like replacing emulate -L zsh with setopt NO_KSH_ARRAYS NO_SH_WORD_SPLIT and get the effect I want.

Give the ZSH-z repo another pull and see if what I’ve done fixes your problem.

Yes, that fixes it - thanks very much. So it seems the problem was triggered by emulate -L zsh. I wonder if that's a bug in zsh, or just a side-effect of using emulate -L zsh. I'm not too clear on exactly what it's supposed to do! Hopefully the new code still works the same way:
setopt LOCAL_OPTIONS NO_KSH_ARRAYS NO_SH_WORD_SPLIT

I think what's going on is that emulate -L zsh turns off PUSHD_IGNORE_DUPS at the moment that cd runs - but you'd figured that out yourself and deserve full credit. setopt LOCAL_OPTIONS NO_KSH_ARRAYS NO_SH_WORD_SPLIT is a more specific way of addressing the fact that this code does not work when the KSH_ARRAYS or SH_WORD_SPLIT options are set. I may eventually rewrite each function to be inherently safe in those situations, but I think the code is easier to read the way it is right now.

That should work. Do post your .zshrc -- we'll save time that way.

If, after you

source /path/to/zsh-z.plugin.zsh

you run

autoload -U compinit && compinit

that should work. If you add

zstyle ':completion:*' menu select

the menus look amazing.

Could you log in to

https://github.com/agkozak/zsh-z/issues/36

and copy and paste the contents of your .zshrc there? GitHub doesn't really forward on file attachments -- I saw the contents of your dircolors file, but nothing else.

By the way, I half wonder if there isn't something a little bit odd about your Cygwin setup. Usually Cygwin makes the C: drive accessible at /cygdrive/c/, not at /c/ (the latter is normal for MSYS2, which is derived from Cygwin). You may have mounted /cygdrive/c/ as /c/ for convenience, though. When I open Cygwin and type

cd /c

I get

cd: no such file or directory: /c

Yes, my /etc/fstab contains this content to mount the C drive under /c:
none / cygdrive binary,posix=0,user 0 0

I've attached my startup files.
files.zip

Well, to start with, you need to have the _zshz file in the same directory as zsh-z.plugin.zsh. It looks as if you keep the latter in your home (~) directory. Is _zshz there? That's the completion function itself.

And yes, in my .zcompdump file, there's

'${ZSHZ_CMD:-${_Z_CMD:-z}}' '_zshz'

and

'zshz' '_zshz'

Both of those reference _zshz -- make sure you've copied that file to the same directory as zsh-z.plugin.zsh, or completion definitely won't happen.

Yes, I could see how you might end up switching back and forth between z and ls. In my case, I use z a lot with directories where I known the structure very well -- since I go there all the time -- and I just don't want to have to type much of it.