zsh-users
 help / color / mirror / code / Atom feed
* dirstack history: loving zsh, crashing zsh...
@ 2006-03-02 17:52 Francisco Borges
  2006-03-02 18:07 ` William Scott
  2006-03-05  9:19 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Francisco Borges @ 2006-03-02 17:52 UTC (permalink / raw)
  To: Zsh User

Hello!

Having to navigate through lot's of nasty dir names, I googled for "zsh
dirstack history", found some guy using ruby to do it (!) hello?! and a
old email from zsh-users [1] that showed a simple way to do it
[1]: <http://www.zsh.org/mla/users/1999/msg00629.html>

I changed a few things, and ended with

if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then
    dirstack=( $(< ~/.zdirs) )
    popd > /dev/null
fi
precmd() {
    dirs -l >! ~/.zdirs # added -l
}

So far so good. Except that I didn't want to change automatically to the
last dir, and zsh's popd didn't seem to allow a way out. So I tried

% typeset -U dirstack

and the shell crashed. (I kid you not!)

This will not happen all the time or with any array. But it does happen
(and I can show you how!), all you need is bunch of identical items on
the top of the dirstack (which you'll get if turn that popd off for a
while).

~ % zsh -f
loki% echo $ZSH_VERSION
4.3.1
loki% dirstack=( $(< ~/.zdirs) )
loki% dirs -vp
0       ~
1       ~
2       ~
3       ~
4       ~
5       ~
6       ~/Desktop
7       /home
8       ~/sys/Firefox/firefox
9       ~/sys/Firefox
10      ~/roskva/outros/images
11      ~/roskva/outros/images/o
12      ~/outros/imagens
13      ~/outros/agenda
14      ~/thesis/EXP/newpar
15      ~/thesis/EXP
loki% typeset -U dirstack
zsh: segmentation fault  zsh -f

Sometimes the shell does not crash (for instance if there aren't a lot
of repeated items in the beginning) and sometimes it will just say:
"free(): invalid pointer 0xb7fdf388!"

[...]

OR you guys are now going to say: "Don't you know you're not supposed to
use typeset with dirstack!!"

Cheers!
Francisco.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dirstack history: loving zsh, crashing zsh...
  2006-03-02 17:52 dirstack history: loving zsh, crashing zsh Francisco Borges
@ 2006-03-02 18:07 ` William Scott
  2006-03-05  9:19 ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: William Scott @ 2006-03-02 18:07 UTC (permalink / raw)
  To: Francisco Borges; +Cc: Zsh User


Hi Francisco:

I wrote a cheezy little function that lets me do this:
I type cd?, and it lists the 20 last visited directories. Then if I type 
cd10, it goes to the one listed on line 10.

This is the command-line version of a shell-gui experiment for OS X that 
Wataru Kagawa and I have been fiddling with, but what you see below works 
on any platform.  I wanted a shared directory stack for all terminal 
sessions.

Example:

% cd?
1 /Users/wgscott
2 /sw/share/xtal/ccp4-6.0/examples/unix/runnable
3 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0/src
4 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0/src/sfcheck_
5 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0
6 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0
7 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0/examples/unix
8 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0/examples/unix/runnable
9 /Users/wgscott/src/ccp4-6/gfortran_appleC-ccp4-6.0/ccp4-6.0/bin
10 /Users/wgscott/src/ccp4-6
11 /sw/fink/dists/unstable/main/finkinfo/shells
12 /Users/wgscott/Xray/mpr_feb24_2006/mpr3/wgs_process
13 /Users/wgscott/Xray/mpr_feb24_2006/mpr3
14 /Users/wgscott/Xray/mpr_feb24_2006
15 /Users/wgscott/Xray
16 /sw/fink/dists/unstable/main/finkinfo/sci
17 /Users/wgscott/Library/sb/Mail
18 /Users/wgscott/Library/sb
19 /sw/src/fink.build/ccp4-gfortran-6.0-1002/ccp4-6.0/x-windows
20 /sw/src/fink.build/ccp4-gfortran-6.0-1002/ccp4-6.0/src

% cd10
/Users/wgscott/src/ccp4-6
%

More info here:

http://www.chemistry.ucsc.edu/~wgscott/mystuff/gdirs.html



On Thu, 2 Mar 2006, Francisco Borges wrote:

> Hello!
>
> Having to navigate through lot's of nasty dir names, I googled for "zsh
> dirstack history", found some guy using ruby to do it (!) hello?! and a
> old email from zsh-users [1] that showed a simple way to do it
> [1]: <http://www.zsh.org/mla/users/1999/msg00629.html>
>
> I changed a few things, and ended with
>
> if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then
>    dirstack=( $(< ~/.zdirs) )
>    popd > /dev/null
> fi
> precmd() {
>    dirs -l >! ~/.zdirs # added -l
> }
>
> So far so good. Except that I didn't want to change automatically to the
> last dir, and zsh's popd didn't seem to allow a way out. So I tried
>
> % typeset -U dirstack
>
> and the shell crashed. (I kid you not!)
>
> This will not happen all the time or with any array. But it does happen
> (and I can show you how!), all you need is bunch of identical items on
> the top of the dirstack (which you'll get if turn that popd off for a
> while).
>
> ~ % zsh -f
> loki% echo $ZSH_VERSION
> 4.3.1
> loki% dirstack=( $(< ~/.zdirs) )
> loki% dirs -vp
> 0       ~
> 1       ~
> 2       ~
> 3       ~
> 4       ~
> 5       ~
> 6       ~/Desktop
> 7       /home
> 8       ~/sys/Firefox/firefox
> 9       ~/sys/Firefox
> 10      ~/roskva/outros/images
> 11      ~/roskva/outros/images/o
> 12      ~/outros/imagens
> 13      ~/outros/agenda
> 14      ~/thesis/EXP/newpar
> 15      ~/thesis/EXP
> loki% typeset -U dirstack
> zsh: segmentation fault  zsh -f
>
> Sometimes the shell does not crash (for instance if there aren't a lot
> of repeated items in the beginning) and sometimes it will just say:
> "free(): invalid pointer 0xb7fdf388!"
>
> [...]
>
> OR you guys are now going to say: "Don't you know you're not supposed to
> use typeset with dirstack!!"
>
> Cheers!
> Francisco.
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dirstack history: loving zsh, crashing zsh...
  2006-03-02 17:52 dirstack history: loving zsh, crashing zsh Francisco Borges
  2006-03-02 18:07 ` William Scott
@ 2006-03-05  9:19 ` Bart Schaefer
  2006-03-06 13:01   ` [zsh] " Francisco Borges
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2006-03-05  9:19 UTC (permalink / raw)
  To: Zsh User

On Mar 2,  6:52pm, Francisco Borges wrote:
}
} % typeset -U dirstack
} 
} and the shell crashed. (I kid you not!)

Since no one else has pointed it out yet, the Right Thing here is

	setopt pushd_ignore_dups
	dirstack=( ${(u)$(< ~/.zdirs)} )
 
} OR you guys are now going to say: "Don't you know you're not supposed
} to use typeset with dirstack!!"

You aren't, but the shell isn't supposed to crash, either.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [zsh] Re: dirstack history: loving zsh, crashing zsh...
  2006-03-05  9:19 ` Bart Schaefer
@ 2006-03-06 13:01   ` Francisco Borges
  2006-03-06 16:51     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Francisco Borges @ 2006-03-06 13:01 UTC (permalink / raw)
  To: Zsh User

» On Sun, Mar 05, 2006 at 01:19AM -0800, Bart Schaefer wrote:

> Since no one else has pointed it out yet, the Right Thing here is
>
> 	setopt pushd_ignore_dups

I have pushd_ignore_dups set, it won't stop that accumulation of
repeated directories at .zdirs (essentially since "dirs" always include
the CWD).

> 	dirstack=( ${(u)$(< ~/.zdirs)} )

But the "u" parameter solves it indeed! Thank you very much for pointing
it.

> } OR you guys are now going to say: "Don't you know you're not supposed
> } to use typeset with dirstack!!"
>
> You aren't, but the shell isn't supposed to crash, either.

Is there any reason for why? I assumed I could treat dirstack as any
other array since, well, the *manual* says dirstack is "a normal array".

Anyway, the problem is solved. Thanks again!

Francisco.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [zsh] Re: dirstack history: loving zsh, crashing zsh...
  2006-03-06 13:01   ` [zsh] " Francisco Borges
@ 2006-03-06 16:51     ` Bart Schaefer
  2006-03-06 18:26       ` [zsh] " Francisco Borges
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2006-03-06 16:51 UTC (permalink / raw)
  To: Zsh User

On Mar 6,  2:01pm, Francisco Borges wrote:
}
} it won't stop that accumulation of repeated directories at .zdirs
} (essentially since "dirs" always include the CWD).

If that's the only issue, then don't use "dirs" at all; instead use
"print $dirstack" which *won't* include the current directory.

} > 	dirstack=( ${(u)$(< ~/.zdirs)} )
} 
} But the "u" parameter solves it indeed! Thank you very much for pointing
} it.

One other thing that just occurred to me is that a single line of
output is unreliable when a directory name may contains whitespace.
You should use:

	print -l $dirstack > ~/.zdirs
and
	dirstack=( ${(uf)"$(< ~/.zdirs)"} )

} > } OR you guys are now going to say: "Don't you know you're not supposed
} > } to use typeset with dirstack!!"
} >
} > You aren't
} 
} Is there any reason for why?

We're having a discussion about that over on zsh-workers right now.  My
position is that $dirstack is just a view on an internal data structure
that cannot be held responsible for the flags set on the parameter, and
therefore for consistency the parameter should not be allowed to have
flags that conflict with that internal structure (it happens to be a
linked list).

} I assumed I could treat dirstack as any other array since, well,
} the *manual* says dirstack is "a normal array".

I think "normal array" just means it's not an "associative array".

The only way to impose consistency with "typeset -U dirstack" on the
underlying internal structure would be to add

    chpwd() { dirstack=( ${(u)dirstack} ) }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [zsh] dirstack history: loving zsh, crashing zsh...
  2006-03-06 16:51     ` Bart Schaefer
@ 2006-03-06 18:26       ` Francisco Borges
  2006-03-07  3:54         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Francisco Borges @ 2006-03-06 18:26 UTC (permalink / raw)
  To: Zsh User

» On Mon, Mar 06, 2006 at 08:51AM -0800, Bart Schaefer wrote:

> On Mar 6,  2:01pm, Francisco Borges wrote:
> }
> } it won't stop that accumulation of repeated directories at .zdirs
> } (essentially since "dirs" always include the CWD).
>
> If that's the only issue, then don't use "dirs" at all; instead use
> "print $dirstack" which *won't* include the current directory.

No, I want the CWD, but that may become a problem because

1. "dirs" includes the CWD even if it is in the $dirstack;
2. "dirstack=( $(< ~/.zdirs) )" bypasses pushd_ignore_dups;
3. some popular directories, triggered this "double entry" many times;
4. pushd_ignore_dups removes only the first double entry.

(perhaps there was no need to explain that...)

So the solution is, AFAIK, really ${(u)...}.

> One other thing that just occurred to me is that a single line of
> output is unreliable when a directory name may contains whitespace.
> You should use:
> 	print -l $dirstack > ~/.zdirs
> 	dirstack=( ${(uf)"$(< ~/.zdirs)"} )

Or "dirs -pl" then.

> } I assumed I could treat dirstack as any other array since, well,
> } the *manual* says dirstack is "a normal array".
>
> I think "normal array" just means it's not an "associative array".

Were you guys surprised a user decided to use typeset on something
described as a "normal" array?

(users are cunning evil creatures and you should know it!)

8-D

Thank you for the explanations!

Cheers!
-- 
Francisco


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [zsh] dirstack history: loving zsh, crashing zsh...
  2006-03-06 18:26       ` [zsh] " Francisco Borges
@ 2006-03-07  3:54         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2006-03-07  3:54 UTC (permalink / raw)
  To: Zsh User

On Mar 6,  7:26pm, Francisco Borges wrote:
}
} Were you guys surprised a user decided to use typeset on something
} described as a "normal" array?

Not especially.  However, it's been six and a half years since the
$dirstack parameter was added, and you're evidently the first person
ever to typeset it.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-03-07  3:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-02 17:52 dirstack history: loving zsh, crashing zsh Francisco Borges
2006-03-02 18:07 ` William Scott
2006-03-05  9:19 ` Bart Schaefer
2006-03-06 13:01   ` [zsh] " Francisco Borges
2006-03-06 16:51     ` Bart Schaefer
2006-03-06 18:26       ` [zsh] " Francisco Borges
2006-03-07  3:54         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).