From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1385 invoked from network); 3 Feb 2006 16:17:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Feb 2006 16:17:05 -0000 Received: (qmail 94553 invoked from network); 3 Feb 2006 16:16:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Feb 2006 16:16:56 -0000 Received: (qmail 10702 invoked by alias); 3 Feb 2006 16:16:53 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22187 Received: (qmail 10685 invoked from network); 3 Feb 2006 16:16:52 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Feb 2006 16:16:52 -0000 Received: (qmail 94262 invoked from network); 3 Feb 2006 16:16:52 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 3 Feb 2006 16:16:50 -0000 Received: from exchange03.csr.com (uuk202166.uk.customer.alter.net [62.189.241.194] (may be forged)) by rly16c.srv.mailcontrol.com (MailControl) with ESMTP id k13FjDYZ030275 for ; Fri, 3 Feb 2006 15:47:28 GMT Received: from csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 3 Feb 2006 15:46:21 +0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: _hosts Date: Fri, 03 Feb 2006 15:46:08 +0000 From: Peter Stephenson Message-ID: X-OriginalArrivalTime: 03 Feb 2006 15:46:21.0524 (UTC) FILETIME=[FAF7F940:01C628D8] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-06-00-02 (www.mailcontrol.com) on 10.67.0.126 I've just run (for the second time) across zstyle -e '*' hosts 'reply=($hosts)' not working because the variable hosts is used locally in the _hosts function. This converts it to _hosts. We need to watch out for more like this. Even more, we need namespaces: I run across problems like this again and again when writing functions for TCP handling, which I use frequently. It's compounded by the inability to pass back values from shell functions in postional parameters. Hmm, we could think of a syntax for the latter... Hmmhmm, being able to insert a parameter into the enclosing scope regardless of values in the current scope would fix it, but it's just the sort of feature that makes the already horrific parameter code even worse. We've been talking about proper namespaces for ages. I've also made the function search ~/.ssh/known_hosts for host names (and strip out IPv4 dot addresses). I've also converted a conditional array assignment into an unconditional one since I didn't see why the former was necessary, but maybe someone can explain. Index: Completion/Unix/Type/_hosts =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_hosts,v retrieving revision 1.5 diff -u -r1.5 _hosts --- Completion/Unix/Type/_hosts 24 Oct 2005 17:09:11 -0000 1.5 +++ Completion/Unix/Type/_hosts 3 Feb 2006 15:36:42 -0000 @@ -1,21 +1,34 @@ #compdef ftp rwho rup xping traceroute host aaaa zone mx ns soa txt -local expl hosts tmp +# avoid calling variable "hosts", it's an obvious candidate for use in +# zstyle -e '*' hosts 'reply=($hosts)' +local expl _hosts tmp -if ! zstyle -a ":completion:${curcontext}:hosts" hosts hosts; then - (( $+_cache_hosts )) || - if (( ${+commands[getent]} )); then - : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${(f)~~"$(_call_program hosts getent hosts 2>/dev/null)"}##[:blank:]#[^[:blank:]]#}}} - else - : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(/dev/null); then - _cache_hosts+=( ${=${(f)tmp}##[:blank:]#[^[:blank:]]#} ) # If you use YP - fi +if ! zstyle -a ":completion:${curcontext}:hosts" hosts _hosts; then + if (( $+_cache_hosts == 0 )); then + # uniquify + typeset -gUa _cache_hosts + if (( ${+commands[getent]} )); then + # pws: we were using the horrible ": ${(A)...:=}" syntax to assign + # to _cache_hosts, overriding the typeset as well as being unreadable + # and having obscure splitting behaviour. Why? We've just + # tested _cache_hosts doesn't exist. + _cache_hosts=(${(s: :)${(ps:\t:)${(f)~~"$(_call_program hosts getent hosts 2>/dev/null)"}##[:blank:]#[^[:blank:]]#}}) + else + _cache_hosts=(${(s: :)${(ps:\t:)${${(f)~~"$(/dev/null); then + _cache_hosts+=( ${=${(f)tmp}##[:blank:]#[^[:blank:]]#} ) # If you use YP fi + fi - hosts=( "$_cache_hosts[@]" ) + if [[ -r ~/.ssh/known_hosts ]]; then + _cache_hosts+=( $(sed -e '/^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]/d' -e 's/[ ,].*//p' ~/.ssh/known_hosts) ) + fi + fi + + _hosts=( "$_cache_hosts[@]" ) fi _wanted hosts expl host \ - compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -a "$@" - hosts + compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -a "$@" - _hosts -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php