From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2310 invoked by alias); 28 Nov 2015 18:54:15 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21006 Received: (qmail 27477 invoked from network); 28 Nov 2015 18:54:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=pa2zgXYn6sqgch6PRZYD5WtgMyR7/kbNQsdNVaVBPCo=; b=WgtHUqPTdh8Ldyj2X2mvnTDytqsmdKfAF8hxODOFePpjSZh18ZjDw32uDPUAXTLC1y 7SJYr/OoLBxcWMH3eheMpleW6jv9/bdjpEn+HeFFV2/eSalTPxy+F1K1hRnybR8Wo7y+ wcr4Uo6R9GFG62zFNIUfrw4lr4DV9RyH8x9GJa/PMrQXl/HvPE2CCek0GeZMNhjqAYT3 uFjgHLa8W27rYMAjIr1dFd6i0lJZ2XfbcznoRUMw1O4wqUC/yvvJ/VMWA6iXhEU3ERTU OdQxzBut4WmoJOHlPIwFzYoG4j7OOp9iEKUOxvnC2+vl+8l0+02yfW22btaWO4Iifffg 5eMA== X-Gm-Message-State: ALoCoQkgZ1XC2kAD/KypNMgWRyAv/gAqAsn6xI956Mejvc5ek7YeTLWz4tOuJkQIMJWtGk6dD2Wg X-Received: by 10.67.6.1 with SMTP id cq1mr66974601pad.78.1448736850436; Sat, 28 Nov 2015 10:54:10 -0800 (PST) From: Bart Schaefer Message-Id: <151128105428.ZM27762@torch.brasslantern.com> Date: Sat, 28 Nov 2015 10:54:28 -0800 In-Reply-To: <20151124103239.GA31057@linux.vnet.ibm.com> Comments: In reply to Dominik Vogt "Help with directory switching functions" (Nov 24, 11:32am) References: <20151124103239.GA31057@linux.vnet.ibm.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: vogt@linux.vnet.ibm.com, Zsh Users Subject: Re: Help with directory switching functions MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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. } } Problems: } } 1. Command lines with multiple command cannot be handled properly } because precmd is just called once for the line, not for each } command. 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". _PWD_A="$PWD:A" 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.