Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Scrolling through directory stack in zsh
- X-seq: zsh-users 1322
- From: Peter Stephenson <pws@xxxxxx>
- To: stephen.talley@xxxxxxxxxxxxxxx (Steve Talley), zsh-users@xxxxxxxxxxxxxxx (Zsh users list)
- Subject: Re: Scrolling through directory stack in zsh
- Date: Tue, 17 Feb 1998 10:03:15 +0100
- In-reply-to: "Steve Talley"'s message of "Mon, 16 Feb 1998 13:57:40 MET." <199802162057.NAA27404@xxxxxxxxxxxxxxxxxxxxxx>
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 <pws@xxxxxx> Tel: +39 50 911239
WWW: http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author