zsh-users
 help / color / mirror / code / Atom feed
From: William Scott <wgscott@chemistry.ucsc.edu>
To: Francisco Borges <f.borges@rug.nl>
Cc: Zsh User <zsh-users@sunsite.dk>
Subject: Re: dirstack history: loving zsh, crashing zsh...
Date: Thu, 2 Mar 2006 10:07:40 -0800 (PST)	[thread overview]
Message-ID: <Pine.OSX.4.61.0603021004030.26996@vanunu.ucsc.edu> (raw)
In-Reply-To: <20060302175252.GA31734@let.rug.nl>


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.
>


  reply	other threads:[~2006-03-02 18:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02 17:52 Francisco Borges
2006-03-02 18:07 ` William Scott [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.OSX.4.61.0603021004030.26996@vanunu.ucsc.edu \
    --to=wgscott@chemistry.ucsc.edu \
    --cc=f.borges@rug.nl \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).