1

Zsh: 5.6.2

I use dirstack from archwiki: https://wiki.archlinux.org/index.php/zsh#Dirstack

All setopts in script are on, script is sourced in ~/.zshrc,

It works before and somehow change index to 0, afaik zsh's array should start from 1.

current unexpected output with 0:

dirs -v
0       ~/.cache/downloads/documents
1       ~
2       ~/.cache/zsh
3       ~/.zsh/scripts

try to cd

cd -<tab>
0 -- ~/.zsh/scripts
1 -- ~/.cache/zsh
2 -- ~

If I choose 1 then it cd to ~/.zsh/scripts instead of ~/.cache/zsh

1

What goes after ~ is not an index in a zsh array variable. See

info zsh 'Filename Expansion'

A '~' by itself is replaced by the value of $HOME. A '~' followed by a '+' or a '-' is replaced by current or previous working directory, respectively.

A '~' followed by a number is replaced by the directory at that position in the directory stack. '~0' is equivalent to '~+', and '~1' is the top of the stack. '~+' followed by a number is replaced by the directory at that position in the directory stack. '~+0' is equivalent to '~+', and '~+1' is the top of the stack. '~-' followed by a number is replaced by the directory that many positions from the bottom of the stack. '~-0' is the bottom of the stack. The PUSHD_MINUS option exchanges the effects of '~+' and '~-' where they are followed by a number.

Though in effect, unless you enable the ksh_arrays or pushd_minus option, ~1 does happen to expand to the same thing as $dirstack[1] while ~0 expands to the same thing as $PWD, ~-0 to the same thing as $dirstack[-1], ~-1 to the same thing as $dirstack[-2].

  • I have option pushd_minus on but it still showing from 0, btw I had multiple zsh session (probably I'm using tmux). I end with writing fuzzy list to choose recent dirs instead. Thanks. – Tuyen Pham Dec 3 '18 at 19:24

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.