zsh-users
 help / color / mirror / code / Atom feed
* Scrolling through directory stack in zsh
@ 1998-02-16 20:57 Steve Talley
  1998-02-17  9:03 ` Peter Stephenson
  1998-02-17  9:54 ` Andrew Main
  0 siblings, 2 replies; 4+ messages in thread
From: Steve Talley @ 1998-02-16 20:57 UTC (permalink / raw)
  To: zsh-users

Hi,

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.

Is this currently possible in zsh?

Steve Talley


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

* Re: Scrolling through directory stack in zsh
  1998-02-16 20:57 Scrolling through directory stack in zsh Steve Talley
@ 1998-02-17  9:03 ` Peter Stephenson
  1998-02-17 10:06   ` Andrew Main
  1998-02-17  9:54 ` Andrew Main
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1998-02-17  9:03 UTC (permalink / raw)
  To: Steve Talley, Zsh users list

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@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: Scrolling through directory stack in zsh
  1998-02-16 20:57 Scrolling through directory stack in zsh Steve Talley
  1998-02-17  9:03 ` Peter Stephenson
@ 1998-02-17  9:54 ` Andrew Main
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Main @ 1998-02-17  9:54 UTC (permalink / raw)
  To: Steve Talley; +Cc: zsh-users

Steve Talley wrote:
>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.
>
>Is this currently possible in zsh?

It could be done with widgets (you'll need a recent beta).

-zefram


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

* Re: Scrolling through directory stack in zsh
  1998-02-17  9:03 ` Peter Stephenson
@ 1998-02-17 10:06   ` Andrew Main
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Main @ 1998-02-17 10:06 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: stephen.talley, zsh-users

Peter Stephenson wrote:
>                                   The hard bit is overloading the
>cursor keys so that they still work as normal, I haven't tried that.

if test -n "$BUFFER"; then
  zle backward-char
  return
endif
...

-zefram


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

end of thread, other threads:[~1998-02-17 10:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-16 20:57 Scrolling through directory stack in zsh Steve Talley
1998-02-17  9:03 ` Peter Stephenson
1998-02-17 10:06   ` Andrew Main
1998-02-17  9:54 ` Andrew Main

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