Zsh Mailing List Archive
Messages sorted by:
Re: Help with directory switching functions
- X-seq: zsh-users 21006
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: vogt@xxxxxxxxxxxxxxxxxx, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Help with directory switching functions
- Date: Sat, 28 Nov 2015 10:54:28 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=pa2zgXYn6sqgch6PRZYD5WtgMyR7/kbNQsdNVaVBPCo=; b=FUVERtd+9WVxja1aP6BEwVH0UMDs3nevj4oBp/1uVjrU/bVRvH9zjeNoqdcFdRTDYZ bKjwoL3dBjWZ6uH8wqKfs8F4B2Mp0qEKfyvrozlc1D2BlyeRNhgsfsDTcGHrRb6ZymQN MMdbE2zQI41z6AI0dDQmiM9uljKCTsLWlGskWc46GPPn3uBRbrwSMdC3DaiJUNqCz7Kr /u9DgWkHPPHw3kfM1RnPbcVeXRcN/0PQbxX/Ll5O/y2906/IGX/FVQGtDs876SkpSOcU CjHgQ145sziLUhg/LrWU+CXygozRM5q8TJPaw2ylBCkdU1JSc3Qr2si6FoMVyHCgZOmP lWPA==
- In-reply-to: <20151124103239.GA31057@linux.vnet.ibm.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20151124103239.GA31057@linux.vnet.ibm.com>
On Nov 24, 11:32am, Dominik Vogt wrote:
} I'm trying to write a function that alternately switches between
} two directories. With "+-" I can repeatedly switch between the
} current directory and the last one where I did anything (type any
} command except switching directories).
} The function makes use of the chpwd and precmd functions.
} 1. Command lines with multiple command cannot be handled properly
} because precmd is just called once for the line, not for each
If you really need to sneak in before (or after) each command rather
than just each command line, read up on TRAPDEBUG, but see below.
} 2. Depending on $HISTCMD is a bit hacky. What I'd really want to
} do is to look at the command being executed and decide
} individually which commands are "interesting" enough to warrant
} recording the current directory.
If you use preexec instead of precmd you can examine the command line
instead of just examining the history event number. I think that
would allow you to start with _IS_CWD_INTERESTING="0" and only set it
to 1 when something interesting happens (if I read correctly right
now, you assume interesting and then zero it in chpwd if nothing else
has happened yet).
Also note that preexec would happen before chpwd, so you'd need some
other corresponding logic changes.
} 3. I'd prefer a shell builtin instead of "readlink".
Or if not that, why not?
Also, possibly use "cd -q" in _swapdir to avoid running chpwd (the work
will already have been done in preexec, I think).
Finally, you might consider using the directory stack; push each of the
directories that seems interesting, and then you can pop back through
them, rather than only having the two most recent to swap between.
Messages sorted by: