zsh-users
 help / color / mirror / code / Atom feed
* How to disable completion of 127.0.0.1 entries from /etc/hosts
@ 2013-03-31  8:29 vermaden
  2013-03-31 10:30 ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: vermaden @ 2013-03-31  8:29 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

Hi all,I use 'static' 127.0.0.1 entries in /etc/hosts to block various things, like described here for example:http://someonewhocares.org/hosts/ Of course ZSH always tries to 'complete' the ssh/scp and always goes thru about 100 000 entries in my /etc/hosts file while the 'real' ones are about 100 maybe at most. My question is: Is there a way to 'tell' ZSH to NOT complete entries beginning with 127.0.0.1 from the /etc/hosts file? Regards,vermaden 

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

* Re: How to disable completion of 127.0.0.1 entries from /etc/hosts
  2013-03-31  8:29 How to disable completion of 127.0.0.1 entries from /etc/hosts vermaden
@ 2013-03-31 10:30 ` Phil Pennock
  2013-03-31 21:07   ` Bart Schaefer
  2013-04-01 20:48   ` vermaden
  0 siblings, 2 replies; 4+ messages in thread
From: Phil Pennock @ 2013-03-31 10:30 UTC (permalink / raw)
  To: vermaden; +Cc: zsh-users

On 2013-03-31 at 10:29 +0200, vermaden wrote:
> Hi all,I use 'static' 127.0.0.1 entries in /etc/hosts to block various
> things, like described here for
> example:http://someonewhocares.org/hosts/ Of course ZSH always tries
> to 'complete' the ssh/scp and always goes thru about 100 000 entries
> in my /etc/hosts file while the 'real' ones are about 100 maybe at
> most. My question is: Is there a way to 'tell' ZSH to NOT complete
> entries beginning with 127.0.0.1 from the /etc/hosts file?
> Regards,vermaden 

Are you aware that the contents of /etc/hosts get loaded into _every_
process doing hostname resolution?  And the file isn't mmap'd in and so
shared, but is instead _read_ into each process, so is not shared
memory?

Seriously, install unbound, use unbound-control and/or home-grown tools
to maintain the list of overrides, make sure the cost of filtering is
only borne once, instead of having zsh also load a 4MB hosts file and
parse it out.  Your system will be faster for _every_ hostname-resolving
package, not just zsh.

Otherwise, use zstyle to set 'hosts':

  zstyle ':completion:*:hosts' hosts $the_hosts_you_care_about

and so override the automatic parsing of /etc/hosts.


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

* Re: How to disable completion of 127.0.0.1 entries from /etc/hosts
  2013-03-31 10:30 ` Phil Pennock
@ 2013-03-31 21:07   ` Bart Schaefer
  2013-04-01 20:48   ` vermaden
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-03-31 21:07 UTC (permalink / raw)
  To: zsh-users

On Mar 31,  6:30am, Phil Pennock wrote:
} Subject: Re: How to disable completion of 127.0.0.1 entries from /etc/host
}
} On 2013-03-31 at 10:29 +0200, vermaden wrote:
} > My question is: Is there a way to 'tell' ZSH to NOT complete
} > entries beginning with 127.0.0.1 from the /etc/hosts file?
} 
} Seriously, install unbound, use unbound-control and/or home-grown tools
} to maintain the list of overrides, make sure the cost of filtering is
} only borne once, instead of having zsh also load a 4MB hosts file and
} parse it out.  Your system will be faster for _every_ hostname-resolving
} package, not just zsh.

Phil's advice is good, but to more directly answer the question:

Zsh only loads from /etc/hosts if it can't find a program named "getent"
in your search path.  So you can control exactly what zsh sees for the
default hosts completion by creating a getent command.  If you already
have getent, you can write a shell function wrapper to filter it (but
zsh decides whether to run it based on the presence of the external
command, even though it will call the function if there is one).

So something like

    getent() {
	command getent "$@" | fgrep -v 127.0.0.1
    }

or

    #!/bin/zsh
    # name this script "getent" and place in a directory in $path
    for key; do fgrep -v 127.0.0.1 /etc/$key; done

You can improve this by testing for the key being "hosts" and do the
fgrep only in that case, but it probably isn't going to make that much
difference given the rest of the context.


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

* Re: How to disable completion of 127.0.0.1 entries from /etc/hosts
  2013-03-31 10:30 ` Phil Pennock
  2013-03-31 21:07   ` Bart Schaefer
@ 2013-04-01 20:48   ` vermaden
  1 sibling, 0 replies; 4+ messages in thread
From: vermaden @ 2013-04-01 20:48 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-users

> On 2013-03-31 at 10:29 +0200, vermaden wrote:
> > Hi all,I use 'static' 127.0.0.1 entries in /etc/hosts to block various
> > things, like described here for
> > example:http://someonewhocares.org/hosts/ Of course ZSH always tries
> > to 'complete' the ssh/scp and always goes thru about 100 000 entries
> > in my /etc/hosts file while the 'real' ones are about 100 maybe at
> > most. My question is: Is there a way to 'tell' ZSH to NOT complete
> > entries beginning with 127.0.0.1 from the /etc/hosts file?
> > Regards,vermaden 
> 
> Are you aware that the contents of /etc/hosts get loaded into _every_
> process doing hostname resolution?  And the file isn't mmap'd in and so
> shared, but is instead _read_ into each process, so is not shared
> memory?
> 
> Seriously, install unbound, use unbound-control and/or home-grown tools
> to maintain the list of overrides, make sure the cost of filtering is
> only borne once, instead of having zsh also load a 4MB hosts file and
> parse it out.  Your system will be faster for _every_ hostname-resolving
> package, not just zsh.
> 
> Otherwise, use zstyle to set 'hosts':
> 
>   zstyle ':completion:*:hosts' hosts $the_hosts_you_care_about
> 
> and so override the automatic parsing of /etc/hosts.

Thank You for Your suggestions and two various solutions, that solves the problem ;)

Regards,
vermaden


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

end of thread, other threads:[~2013-04-01 20:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-31  8:29 How to disable completion of 127.0.0.1 entries from /etc/hosts vermaden
2013-03-31 10:30 ` Phil Pennock
2013-03-31 21:07   ` Bart Schaefer
2013-04-01 20:48   ` vermaden

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