zsh hostname completion via DNS zonetransfer

From: Christian Wenke (christian.wenke@gmx.de)
Date: Sat Aug 02 2003 - 07:44:28 CEST


Moin moin,

wie ich gestern Abend Wuffel im Marvins versprochen hab, hier das,
was zu tun ist, um in der zsh die hostname completion via DNS-zonetransfer
zu machen.

Als erstes, ein eigenes zfunc modul für hostname completion:

-rwxr-x--- 1 cw81 cw81 413 Aug 1 2002 $HOME/.zfunc/_hosts
-----------------------------------------------------------------------------
local expl hosts
if ! zstyle -a ":completion:${curcontext}:hosts" hosts hosts; then
        (( $+_cache_hosts )) ||
        : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(host -l $(awk '/search/ { print $2 }' < /etc/resolv.conf) 2>/dev/null | awk '{ print $3,
        $1}')"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
        hosts=( "$_cache_hosts[@]" )
fi
_wanted hosts expl host \
        compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" -a hosts
-----------------------------------------------------------------------------

Dann:

in der $HOME/.zshrc

-----------------------------------------------------------------------------
fpath=(~/.zfunc $fpath)

# Autoload all shell functions from all directories in $fpath (following
# symlinks) that have the executable bit on (the executable bit is not
# necessary, but gives you an easy way to stop the autoloading of a
# particular shell function). $fpath should not be empty for this to work.
for func in $^fpath/*(N-:t); autoload $func

-----------------------------------------------------------------------------

In der Standard-/Beispiel-Konfiguration läuft die hostname completion über
eine Variable $hosts, in der die zu vervollständigenden hostnamen drinstehen.
Damit dies funktioniert wird ein zstyle gesetzt:

zstyle '*' hosts $hosts

dieser muss für das Modul für die DNS zonetransfer basierte completion
auskommentiert werden, das modul macht schon alles.

Achja, damit das ganze funktioniert, sollte man natürlich einen zonetransfer
vom entsprechenden DNS machen dürfen. :)

Das lässt sich aber leicht überprüfen:

host -l $(awk '/search/ { print $2 }' < /etc/resolv.conf)

Viel Spaß,

        Christian

Disclaimer:

Ich bin nicht verantwortlich für irgendwelche kaputtkonfigurierten shells :-)

-- 
-----------------------------------------------------------------------------
Christian Wenke <christian.wenke@gmx.de>
Beentweg 20
26135 Oldenburg
-----------------------------------------------------------------------------


This archive was generated by hypermail 2.1.7 : Sat Aug 02 2003 - 07:45:12 CEST