Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Rehash after installs



On Fri, Aug 12, 2011 at 11:53:00PM -0700, Micah Elliott wrote:

> 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.

Hi Micah,

This is a nice idea.

On debian, "dpkg -i" will also install packages (beside apt-get),
and especially on ubuntu, users often utilize synaptic and the
software-center for that (but imho these graphical installers can be
ignored for the reason that their users do not tend to have a shell
always open somewhere)

Best regards

Sebastian Tramp

-- 
Sebastian Tramp - Department of Computer Science; University of Leipzig
WebID: http://sebastian.tramp.name  Tel. (Fax): +49 341 97 323-66 (-29)



Messages sorted by: Reverse Date, Date, Thread, Author