From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23046 invoked by alias); 17 Jun 2018 22:20:42 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43044 Received: (qmail 20557 invoked by uid 1010); 17 Jun 2018 22:20:42 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f68.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.68):SA:0(-1.9/5.0):. Processed in 1.387151 secs); 17 Jun 2018 22:20:42 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=oAt+Mu3s1WfMLWcAIEc+SQTQWB2rYi7Ez4gMl97EaPk=; b=NCVGHaVwKWbkM+i8+xaxvx/+P6hGk3Rw0t+sD3pKs81mMUdzSZx2pMWs1K9AM7ADcd RWMbj4PSg4zOd68L15I22LmJNJEO42iSYjinSD/gflpn/ZN3WPUg9DkaeYVZc+VbACrf h85o2LVgGo/XWvfkoJyurkMxoF0q7/CVd6JXFmLLISD+/Iu1azeSALvD80sc5A1x1b9F klr6DdLygh6xeaeRy17zYRL1VxdD4aTO12hq9z0fDQDk3f9ZGCLstSpj12FaRLUBoiNV snng2raQ47knCqQLqf4ha2BeueyEhKJWAFkxoOO4x0c2SclCT9EMflcSSIDnkE33TSdN qCPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=oAt+Mu3s1WfMLWcAIEc+SQTQWB2rYi7Ez4gMl97EaPk=; b=uNmRYT+/iE29f9lFapezvdKqsqwm0pyXVCBepl7+1PnYTc4n+Lyvol3c1LU+Abv3ZJ S10w8hMz3U2BQzfmWgZBbf03hMVH49DgC7rz/+7XKpI6Z2tMh3abaTzK5zma4STkqCY6 XWgZHz/AzTLMeV3ul61LJGPKSdElUjdqK10bqfwHwoO3Eu9SBLzAzEVpaH9ube63SkKo NEBMj/RgCUgkQebzi5SjIUB1mnaZBJG09Jd08oZOdkJey9ZkePD/zb8WJy0ka3AIaYOd WNKDC1F5yE24e5UYC/wdgGztHCZsZAV4DMr6kv2vOGCXeekQWRBOLPSyevfEedZ3J8iB dfkQ== X-Gm-Message-State: APt69E3UGPcRZ9gwqojG3KAJwr2t3bNHqNTSqmuc+ZgPhue8JjsM2FUo hBy+jTDGEjJqOcFVIlGHfDZJoQLfQqM= X-Google-Smtp-Source: ADUXVKLCGjf0x7x+JxWWCLtFfeak2eC9BGe5iohzeVwnRSUxNBjZnIHgc/36D6XHzJB8TI8ow6x/fw== X-Received: by 2002:a24:2e43:: with SMTP id i64-v6mr7895142ita.0.1529274038390; Sun, 17 Jun 2018 15:20:38 -0700 (PDT) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] Completion: Add _hostname (+ a question) Message-Id: <6B9F94D1-6E43-4970-8571-C935B6167EB0@dana.is> Date: Sun, 17 Jun 2018 17:20:37 -0500 To: Zsh workers X-Mailer: Apple Mail (2.3273) This is a new completion function for the hostname command. For Dragonfly i needed to complete locally bound IP addresses (see = bottom). The _bind_addresses type function was presumably intended for just this kind = of thing... except that all it does on many systems is call _hosts. That = doesn't seem appropriate at all in cases like this, nor in the cases where the = function is already being used, such as `ssh -b` and `rsync --address`. Instead of doing my own thing here, would there be any issue with my = changing _bind_addresses to unconditionally return the actual interface addresses = using a similar method (maybe with a few flags to control inclusion of = loop-backs, &c.)? If so, i'll prepare an improved patch. dana diff --git a/Completion/Unix/Command/_hostname = b/Completion/Unix/Command/_hostname new file mode 100644 index 000000000..22127fed7 --- /dev/null +++ b/Completion/Unix/Command/_hostname @@ -0,0 +1,77 @@ +#compdef hostname + +local ret=3D1 +local -a context line state state_descr args aopts tmp +local -A opt_args + +if _pick_variant net-tools=3D--yp unix --help; then + args=3D( + '(: * -)'{-h,--help}'[display help information]' + '(: * -)'{-V,--version}'[display version information]' + + '(g)' # Get + '(: gs s)'{-A,--all-fqdns}'[display FQDNs resolved from network = interface addresses]' + '(: gs s)'{-d,--domain}'[display DNS domain only]' + '(: gs s)'{-f,--fqdn,--long}'[display host name with DNS domain = (FQDN)]' + '(: gs s)'{-i,--ip-address}'[display IP addresses for host (via DNS = resolution)]' + '(: gs s)'{-I,--all-ip-addresses}'[display IP addresses for host = (via network interfaces)]' + '(: gs s)'{-s,--short}'[display short host name only]' + + '(gs)' # Get/set + '(g)'{-y,--yp,--nis}'[display NIS domain only]' + + s # Set + '(-b --boot g)'{-b,--boot}'[always set a host name]' + '(: -F --file g)'{-F+,--file=3D}'[read host name to set from = specified file]: :_files' + + o + '(-F --file g)1: :->host-or-domain' + ) +else + aopts=3D( -A '-*' ) + args=3D( + '(-4 -6 -d -f -i -r -s)1: :_guard "^-*" "host name"' + '(: -4 -6 -d -f)-s[display short host name only]' + ) + + case $OSTYPE in + darwin*|freebsd*) + args+=3D( + '(: -d -s)-f[display host name with DNS domain (FQDN)]' + ) + ;| # MATCH AGAIN + freebsd*) + args+=3D( + '(: -f -s)-d[display DNS domain only]' + ) + ;; + dragonfly*) + args+=3D( + '(: -6 -r)-4[use first IPv4 address on interface (with -i)]' + '(: -4 -r)-6[use first IPv6 address on interface (with -i)]' + '(: -r)-i+[retrieve host name via specified interface]: = :_net_interfaces' + '(: -4 -6 -i)-r+[retrieve host name via specified IP address]: = :->ip-address' + ) + ;; + esac +fi + +_arguments -s -S $aopts : $args && ret=3D0 + +case $state in + host-or-domain) + [[ -prefix -* ]] || + if [[ -n ${opt_args[(i)*-(-y|--yp|--nis)]} ]]; then + _message -e nis-domains 'NIS domain' && ret=3D0 + else + _message -e host-names 'host name' && ret=3D0 + fi + ;; + ip-address) + # @todo Should we have a proper type function for local IPs? + tmp=3D( ${(f)"$( _call_program ip-addresses ifconfig -a )"} ) + tmp=3D( ${(@M)tmp##(|[[:space:]]##)inet(|6)(|:)[[:space:]]*} ) + tmp=3D( ${(@)tmp#*inet(|6)(|:)[[:space:]]##} ) + tmp=3D( ${(@)tmp%%[^0-9A-Fa-f:.]*} ) + tmp=3D( ${(@u)${(@)tmp//:/\\:}} ) + _describe -t ip-addresses 'IP address' tmp && ret=3D0 + ;; +esac + +return ret