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

Re: Rehash after installs



On Sat, Aug 13, 2011 at 09:05:35AM +0200, Sebastian Tramp wrote:

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

Another (perhaps nicer) solution would be to "rehash" if command
completion failed, and then retry completion after that.

This way even with a GUI installation program you'll get current
completion info. I've no idea how to implement it though; so if someone
does it (or has already done it), please let me know.

GI

-- 
Energizer Bunny arrested - charged with battery.



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