BTS

Issue1567

Title grml-zshrc: broken dirstack handling
Priority bug Status resolved
Superseder Nosy List ft, mika
Assigned To ft Topics

Created on 2015-07-16.21:24:07 by mika, last changed 2015-08-11.10:27:57 by mika.

Messages
msg5227 (view) Author: mika Date: 2015-08-11.10:27:56
Seems to work as needed, thanks Frank!
msg5226 (view) Author: mika Date: 2015-08-11.10:20:46
Supposed to be fixed by:

http://git.grml.org/?p=grml-etc-core.git;a=commit;h=ead1a063a2fb9189bc697be2120b24cf3f3dd56a
http://git.grml.org/?p=grml-etc-core.git;a=commit;h=cdc48e89c5ae0fe84ae458a20ebdd36282a2e81c

Thanks, Frank!
msg5197 (view) Author: mika Date: 2015-07-30.14:32:48
Thanks for your patch, Frank. Issue doesn't seem to be resolved yet.
C/P of a plain Debian system with bash as default shell and switching to zsh
explicitely (no other shell session present and I typed 'exit' explicitly to
make it obvious what's going on):

root@debian-jessie-plain:~# zsh
+/etc/zsh/zshrc:1594> DIRSTACKSIZE=20 
+/etc/zsh/zshrc:1595> DIRSTACKFILE=/root/.zdirs 
+/etc/zsh/zshrc:1597> typeset -gaU GRML_PERSISTENT_DIRSTACK
+/etc/zsh/zshrc:1624> [[ -f /root/.zdirs ]]
+/etc/zsh/zshrc:1624> [[ 0 -eq 0 ]]
+/etc/zsh/zshrc:1628> [[ -d '' ]]
+/etc/zsh/zshrc:1630> [[ -d '' ]]
+/etc/zsh/zshrc:1633> zstyle -T :grml:chpwd:dirstack filter-on-load
+/etc/zsh/zshrc:1645> set +x
root@debian-jessie-plain ~ # cat .zdirs 
/root
root@debian-jessie-plain ~ # cd /etc/zsh
+chpwd:2:else> ((  20 <= 0  ))
+chpwd:3:else> [[ -z /root/.zdirs ]]
+chpwd:4:else> grml_dirstack_filter /etc/zsh
+grml_dirstack_filter:1:> setopt local_options xtrace
+grml_dirstack_filter:2:> local -a exclude
+grml_dirstack_filter:3:> local filter entry
+grml_dirstack_filter:4:if> zstyle -s :grml:chpwd:dirstack filter filter
+grml_dirstack_filter:7:if> zstyle -a :grml:chpwd:dirstack exclude exclude
+grml_dirstack_filter:12:> return 1
+chpwd:5:else> GRML_PERSISTENT_DIRSTACK=( /etc/zsh ) 
+chpwd:8:else> print -l /etc/zsh
root@debian-jessie-plain /etc/zsh # cd /usr/sbin
+chpwd:2:else> ((  20 <= 0  ))
+chpwd:3:else> [[ -z /root/.zdirs ]]
+chpwd:4:else> grml_dirstack_filter /usr/sbin
+grml_dirstack_filter:1:> setopt local_options xtrace
+grml_dirstack_filter:2:> local -a exclude
+grml_dirstack_filter:3:> local filter entry
+grml_dirstack_filter:4:if> zstyle -s :grml:chpwd:dirstack filter filter
+grml_dirstack_filter:7:if> zstyle -a :grml:chpwd:dirstack exclude exclude
+grml_dirstack_filter:12:> return 1
+chpwd:5:else> GRML_PERSISTENT_DIRSTACK=( /usr/sbin /etc/zsh ) 
+chpwd:8:else> print -l /usr/sbin /etc/zsh
root@debian-jessie-plain /usr/sbin # exit
root@debian-jessie-plain:~# cat .zdirs 
/usr/sbin
/etc/zsh
root@debian-jessie-plain:~# zsh
+/etc/zsh/zshrc:1594> DIRSTACKSIZE=20 
+/etc/zsh/zshrc:1595> DIRSTACKFILE=/root/.zdirs 
+/etc/zsh/zshrc:1597> typeset -gaU GRML_PERSISTENT_DIRSTACK
+/etc/zsh/zshrc:1624> [[ -f /root/.zdirs ]]
+/etc/zsh/zshrc:1624> [[ 0 -eq 0 ]]
+/etc/zsh/zshrc:1628> [[ -d '' ]]
+/etc/zsh/zshrc:1630> [[ -d '' ]]
+/etc/zsh/zshrc:1633> zstyle -T :grml:chpwd:dirstack filter-on-load
+/etc/zsh/zshrc:1645> set +x
root@debian-jessie-plain ~ # cat .zdirs 
/usr/sbin
/etc/zsh
root@debian-jessie-plain ~ # cd -
No matches for: `directory stack', `local directory', or `file'

root@debian-jessie-plain ~ # exit    
root@debian-jessie-plain:~# zsh
+/etc/zsh/zshrc:1594> DIRSTACKSIZE=20 
+/etc/zsh/zshrc:1595> DIRSTACKFILE=/root/.zdirs 
+/etc/zsh/zshrc:1597> typeset -gaU GRML_PERSISTENT_DIRSTACK
+/etc/zsh/zshrc:1624> [[ -f /root/.zdirs ]]
+/etc/zsh/zshrc:1624> [[ 0 -eq 0 ]]
+/etc/zsh/zshrc:1628> [[ -d '' ]]
+/etc/zsh/zshrc:1630> [[ -d '' ]]
+/etc/zsh/zshrc:1633> zstyle -T :grml:chpwd:dirstack filter-on-load
+/etc/zsh/zshrc:1645> set +x
root@debian-jessie-plain ~ # cat .zdirs 
/usr/sbin
/etc/zsh
root@debian-jessie-plain ~ # cd /usr/bin
+chpwd:2:else> ((  20 <= 0  ))
+chpwd:3:else> [[ -z /root/.zdirs ]]
+chpwd:4:else> grml_dirstack_filter /usr/bin
+grml_dirstack_filter:1:> setopt local_options xtrace
+grml_dirstack_filter:2:> local -a exclude
+grml_dirstack_filter:3:> local filter entry
+grml_dirstack_filter:4:if> zstyle -s :grml:chpwd:dirstack filter filter
+grml_dirstack_filter:7:if> zstyle -a :grml:chpwd:dirstack exclude exclude
+grml_dirstack_filter:12:> return 1
+chpwd:5:else> GRML_PERSISTENT_DIRSTACK=( /usr/bin ) 
+chpwd:8:else> print -l /usr/bin
root@debian-jessie-plain /usr/bin # cat ~/.zdirs 
/usr/bin
root@debian-jessie-plain /usr/bin # exit
root@debian-jessie-plain:~# cat ~/.zdirs 
/usr/bin
root@debian-jessie-plain:~#
msg5193 (view) Author: ft Date: 2015-07-20.22:16:08
On IRC, I asked mika for to try this:

diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index b6c8375..72fde6e 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -1622,7 +1622,7 @@ if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]]
; then
     # directories from the saved dir-stack file.
     dirstack=( ${(f)"$(< $DIRSTACKFILE)"}(N) )
     # "cd -" won't work after login by just setting $OLDPWD, so
-    [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
+    [[ -d $dirstack[1] ]] && cd -q $dirstack[1] && cd -q $OLDPWD
 fi

 if zstyle -T ':grml:chpwd:dirstack' filter-on-load; then

His reply:

> looks better AFAICT! just /home/mika is in the "temporary" dirstack
> (not ~/.zdirs though!) twice, unsure whether that's wanted or not.

So that's a start.

The idea is to use "-q" so the implicit chdirs don't trigger the
chpwd() hook function.

Mika: If you can reproduce the "weird directories in dirstack" issue,
please try the following and paste the result in here (it'll produce
a fair bit of output on the commandline as zsh starts up):

diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index 72fde6e..ebc5678 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -1588,12 +1588,13 @@ isgrmlcd && HISTSIZE=500  || HISTSIZE=5000
 isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
 
 # dirstack handling
-
+set -x
 DIRSTACKSIZE=${DIRSTACKSIZE:-20}
 DIRSTACKFILE=${DIRSTACKFILE:-${ZDOTDIR:-${HOME}}/.zdirs}
 
 typeset -gaU GRML_PERSISTENT_DIRSTACK
 function grml_dirstack_filter() {
+    setopt local_options xtrace
     local -a exclude
     local filter entry
     if zstyle -s ':grml:chpwd:dirstack' filter filter; then
@@ -1608,6 +1609,7 @@ function grml_dirstack_filter() {
 }
 
 chpwd() {
+    setopt local_options xtrace
     (( $DIRSTACKSIZE <= 0 )) && return
     [[ -z $DIRSTACKFILE ]] && return
     grml_dirstack_filter $PWD && return
@@ -1637,6 +1639,7 @@ if zstyle -T ':grml:chpwd:dirstack' filter-on-load; then
 else
     GRML_PERSISTENT_DIRSTACK=( "${dirstack[@]}" )
 fi
+set +x
 
 # directory based profiles
 

Regards, Frank
msg5192 (view) Author: mika Date: 2015-07-16.21:24:07
Our recent changes to dirstack handling in grml-zshrc have broken the ~/.zdirs
handling. The DIRSTACKFILE is always overwritten every time you open a new zsh
session, so the directory history is always(?) lost.

Starting three shell sessions one after the other:

mika@heart ~ % cat ~/.zdirs
/home/mika
/home/grml/git-grml/grml-etc-core
mika@heart ~ % cd -
completing directory stack
0 -- /grml/git-grml/grml-etc-core
1 -- /home/grml/git-grml/grml-etc-core

mika@heart ~ % cd /grml/git-grml/grml2usb
chpwd(): Switching to profile: grml
mika@heart ~ggit/grml2usb (git)-[master] % cat ~/.zdirs
/grml/git-grml/grml2usb
/home/mika
/home/grml/git-grml/grml-etc-core
mika@heart ~ggit/grml2usb (git)-[master] % 

mika@heart /home/grml/git-grml/grml2usb (git)-[master] % cd /tmp
mika@heart /tmp % 
mika@heart /tmp % cat ~/.zdirs
/home/grml/git-grml/grml2usb
/grml/git-grml/grml2usb

Something is wrong, I can't spot the source of the bug yet though, reporting as
suggested by Frank, thx :)
History
Date User Action Args
2015-08-11 10:27:57mikasetstatus: fixed-in-git -> resolved
nosy: mika, ft
messages: + msg5227
2015-08-11 10:20:46mikasetstatus: chatting -> fixed-in-git
nosy: mika, ft
messages: + msg5226
2015-07-30 14:32:49mikasetnosy: mika, ft
messages: + msg5197
2015-07-20 22:16:08ftsetstatus: unread -> chatting
nosy: mika, ft
messages: + msg5193
2015-07-16 21:24:07mikacreate