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

Re: How to disable completion of 127.0.0.1 entries from /etc/hosts



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.



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