zsh-users
 help / color / mirror / code / Atom feed
From: Micah Elliott <micah@membean.com>
To: zsh-users@zsh.org
Subject: Rehash after installs
Date: Fri, 12 Aug 2011 23:53:00 -0700	[thread overview]
Message-ID: <CAELbujoK2oXr5cOZs1r4Avh2OGeOnAki1iTROx+hC9pswPTJ8w@mail.gmail.com> (raw)

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="$?"
	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+=rehash-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.

-- 
twitter:@Membean  |  email:Micah@Membean.com  |  http://Membean.com
Remember your words with Membean! Three free days of learning!


             reply	other threads:[~2011-08-13  6:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-13  6:53 Micah Elliott [this message]
2011-08-13  7:05 ` Sebastian Tramp
2011-08-14  4:03   ` gi1242+zsh
2011-08-14  4:37     ` Mikael Magnusson
2011-08-14 14:46       ` Gautam Iyer
2011-08-14 15:02         ` Mikael Magnusson
2011-08-15  2:47           ` gi1242+zsh

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=CAELbujoK2oXr5cOZs1r4Avh2OGeOnAki1iTROx+hC9pswPTJ8w@mail.gmail.com \
    --to=micah@membean.com \
    --cc=zsh-users@zsh.org \
    /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).