zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: How to disable completion of 127.0.0.1 entries from /etc/hosts
Date: Sun, 31 Mar 2013 14:07:50 -0700	[thread overview]
Message-ID: <130331140750.ZM30293@torch.brasslantern.com> (raw)
In-Reply-To: <20130331103044.GA25277@redoubt.spodhuis.org>

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.


  reply	other threads:[~2013-03-31 21:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-31  8:29 vermaden
2013-03-31 10:30 ` Phil Pennock
2013-03-31 21:07   ` Bart Schaefer [this message]
2013-04-01 20:48   ` vermaden

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=130331140750.ZM30293@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).