zsh-users
 help / color / mirror / code / Atom feed
* Rehash after installs
@ 2011-08-13  6:53 Micah Elliott
  2011-08-13  7:05 ` Sebastian Tramp
  0 siblings, 1 reply; 7+ messages in thread
From: Micah Elliott @ 2011-08-13  6:53 UTC (permalink / raw)
  To: zsh-users

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!


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-13  6:53 Rehash after installs Micah Elliott
@ 2011-08-13  7:05 ` Sebastian Tramp
  2011-08-14  4:03   ` gi1242+zsh
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Tramp @ 2011-08-13  7:05 UTC (permalink / raw)
  To: Micah Elliott; +Cc: zsh-users

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)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-13  7:05 ` Sebastian Tramp
@ 2011-08-14  4:03   ` gi1242+zsh
  2011-08-14  4:37     ` Mikael Magnusson
  0 siblings, 1 reply; 7+ messages in thread
From: gi1242+zsh @ 2011-08-14  4:03 UTC (permalink / raw)
  To: zsh-users

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-14  4:03   ` gi1242+zsh
@ 2011-08-14  4:37     ` Mikael Magnusson
  2011-08-14 14:46       ` Gautam Iyer
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2011-08-14  4:37 UTC (permalink / raw)
  To: gi1242+zsh; +Cc: zsh-users

On 14 August 2011 06:03,  <gi1242+zsh@gmail.com> wrote:
> 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.

You mean something like
zstyle ':completion:*' rehash true
?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-14  4:37     ` Mikael Magnusson
@ 2011-08-14 14:46       ` Gautam Iyer
  2011-08-14 15:02         ` Mikael Magnusson
  0 siblings, 1 reply; 7+ messages in thread
From: Gautam Iyer @ 2011-08-14 14:46 UTC (permalink / raw)
  To: zsh-users

On Sun, Aug 14, 2011 at 06:37:52AM +0200, Mikael Magnusson wrote:

>> 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.
> 
> You mean something like
> zstyle ':completion:*' rehash true

Indeed! Thanks for telling me about this.

The man page however seems to say that a rehash is issued on *every*
external command completion request. Is it possible to rehash only on
every *failed* external command completion request.

I guess it doesn't really matter so much as I can't (yet) notice too
much of a performance penalty.

Thanks,

GI

-- 
Top Ten New Intel Slogans For The Pentium:
3.9998245917 Division Considered Harmful


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-14 14:46       ` Gautam Iyer
@ 2011-08-14 15:02         ` Mikael Magnusson
  2011-08-15  2:47           ` gi1242+zsh
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2011-08-14 15:02 UTC (permalink / raw)
  To: Gautam Iyer; +Cc: zsh-users

On 14 August 2011 16:46, Gautam Iyer <gi1242+zsh@gmail.com> wrote:
> On Sun, Aug 14, 2011 at 06:37:52AM +0200, Mikael Magnusson wrote:
>
>>> 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.
>>
>> You mean something like
>> zstyle ':completion:*' rehash true
>
> Indeed! Thanks for telling me about this.
>
> The man page however seems to say that a rehash is issued on *every*
> external command completion request. Is it possible to rehash only on
> every *failed* external command completion request.
>
> I guess it doesn't really matter so much as I can't (yet) notice too
> much of a performance penalty.

Sure, but then you would still get incorrect completions as long as
you typed something that can be completed to another command, ie you
installed foobara and had foobaza already, so fooba<tab> would give
you foobaza, while foobar<tab> would give foobara.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Rehash after installs
  2011-08-14 15:02         ` Mikael Magnusson
@ 2011-08-15  2:47           ` gi1242+zsh
  0 siblings, 0 replies; 7+ messages in thread
From: gi1242+zsh @ 2011-08-15  2:47 UTC (permalink / raw)
  To: zsh-users

On Sun, Aug 14, 2011 at 05:02:13PM +0200, Mikael Magnusson wrote:

>> The man page however seems to say that a rehash is issued on *every*
>> external command completion request. Is it possible to rehash only on
>> every *failed* external command completion request.
>>
>> I guess it doesn't really matter so much as I can't (yet) notice too
>> much of a performance penalty.
> 
> Sure, but then you would still get incorrect completions as long as
> you typed something that can be completed to another command, ie you
> installed foobara and had foobaza already, so fooba<tab> would give
> you foobaza, while foobar<tab> would give foobara.

That's true! I guess completion style rehash is the way to go.

Thanks,

Gautam

-- 
Modern Computer Viruses:
Texas Virus -- Makes sure it's bigger than any other file.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-15  2:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-13  6:53 Rehash after installs Micah Elliott
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

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