zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@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
Date: Tue, 17 Feb 1998 10:03:15 +0100	[thread overview]
Message-ID: <199802170903.KAA16968@hydra.ifh.de> (raw)
In-Reply-To: "Steve Talley"'s message of "Mon, 16 Feb 1998 13:57:40 MET." <199802162057.NAA27404@empire.Central.Sun.COM>

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


  reply	other threads:[~1998-02-17  9:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-16 20:57 Steve Talley
1998-02-17  9:03 ` Peter Stephenson [this message]
1998-02-17 10:06   ` Andrew Main
1998-02-17  9:54 ` Andrew Main

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=199802170903.KAA16968@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=stephen.talley@Central.Sun.COM \
    --cc=zsh-users@math.gatech.edu \
    /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).