From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16103 invoked from network); 17 Feb 1998 09:23:16 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 17 Feb 1998 09:23:16 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id EAA19973; Tue, 17 Feb 1998 04:02:58 -0500 (EST) Resent-Date: Tue, 17 Feb 1998 04:01:15 -0500 (EST) Message-Id: <199802170903.KAA16968@hydra.ifh.de> To: stephen.talley@Central.Sun.COM (Steve Talley), zsh-users@math.gatech.edu (Zsh users list) Subject: Re: Scrolling through directory stack in zsh In-reply-to: "Steve Talley"'s message of "Mon, 16 Feb 1998 13:57:40 MET." <199802162057.NAA27404@empire.Central.Sun.COM> Date: Tue, 17 Feb 1998 10:03:15 +0100 From: Peter Stephenson Resent-Message-ID: <"k2o-p1.0.Lt4.Q7Lwq"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1322 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Steve Talley wrote: > Does zsh support the ability to cycle through the directory stack, in > the same way that it can cycle through the history list? > > Currently I have the up and down arrows bound to scroll through the > history list. What I'd like is to have the left and right arrows, if > the line is blank, to scroll through the directory stack. Just like > the history list, each time I hit the right or left arrow, the > directory would appear on the command line. And if I hit enter at that > point, then zsh will cd to that directory. You can get at least some of the effect of that using the new zle widget code available from 3.1.2. The hard bit is overloading the cursor keys so that they still work as normal, I haven't tried that. However, the following (using ^x^n and ^x^p) will insert previous or subsequent directory entries on the command line, and if you have AUTO_CD set hitting return will take you there. You may want either to set AUTO_PUSHD as well, or to make the shell insert a 'pushd' before the directory name (change the BUFFER= part), or the cd will wipe out the first entry in the stack. Note that these functions will simply wipe out anything on the command line when called. Some test like '[[ -n $BUFFER ]] && zle push-line' might be sensible. show-prev-dir() { (( dir_no )) || dir_no=1; local dirs dirs=($(dirs)) [[ $((--dir_no)) < 1 ]] && dir_no=$#dirs BUFFER=$dirs[$dir_no] } show-next-dir() { (( dir_no )) || dir_no=0; local dirs dirs=($(dirs)) [[ $((++dir_no)) > $#dirs ]] && dir_no=1 BUFFER=$dirs[$dir_no] } zle -N show-next-dir zle -N show-prev-dir bindkey "^X^p" show-prev-dir bindkey "^X^n" show-next-dir -- Peter Stephenson Tel: +39 50 911239 WWW: http://www.ifh.de/~pws/ Gruppo Teorico, Dipartimento di Fisica Piazza Torricelli 2, 56100 Pisa, Italy