From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11040 invoked by alias); 13 Aug 2011 06:53:27 -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: 16209 Received: (qmail 18697 invoked from network); 13 Aug 2011 06:53:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at micahelliott.com does not designate permitted sender hosts) MIME-Version: 1.0 Sender: mde@micahelliott.com From: Micah Elliott Date: Fri, 12 Aug 2011 23:53:00 -0700 X-Google-Sender-Auth: 6FwqJ0JOK1h-VHd5neQM0fD0Fz0 Message-ID: Subject: Rehash after installs To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I've found that most tools don't rehash after they install something. aptitude is guilty (if you want to call it that), but other tools like "gem" are more friendly (well, I believe RVM is the one providing this wrapper.) % whence -f gem gem () { local result command gem "$@" result=3D"$?" hash -r # Update so newly installed util is now active! return $result } Cool idea! I'm to the point where I mostly always remember now to rehash after I install anything. But it's still nice to do this automatically when possible. Rather than try to wrap all the system utils that install things, I'd like a reasonably generic way to do it. I'm just checking with the list here to see if this looks like a safe way to do such checking, and make sure there's nothing glaringly wrong about it... typeset -ga precmd_functions rehash-last-install() { fc -l -1 |grep -q install && { print rehash-ing; rehash } } precmd_functions+=3Drehash-last-install Basically, this just looks at the last command (via fc) to see if there was an "install" somewhere in it, and runs itself after every command. It's going to rehash more often than necessary (false positives), but I can't think of why that would be a bad thing since rehashing looks pretty cheap. --=20 twitter:@Membean=C2=A0 |=C2=A0 email:Micah@Membean.com=C2=A0 |=C2=A0 http:/= /Membean.com Remember your words with Membean! Three free days of learning!