zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: option cache in netcat completion
Date: Sat, 24 Mar 2018 14:45:33 +0100	[thread overview]
Message-ID: <7738.1521899133@thecus> (raw)

This is a fairly minor tweak to netcat completion for something that
confused me.

If you have netcat installed as nc but not as netcat and try:
  netcat -<tab>
It creates an empty array for the cache. Thereafter, option completion
won't work after nc either. This change uses $#array instead of $+array
but I've also renamed the variable with a _cache prefix to be more in
line with other functions that do caching.

The options could really do with filling out but it would have to be a
mess to handle GNU netcat, traditional netcat, each of the BSDs and
openbsd netcat installed on Linux. And socat is better anyway.

Oliver

diff --git a/Completion/Unix/Command/_netcat b/Completion/Unix/Command/_netcat
index 4e4006b30..250d4c85d 100644
--- a/Completion/Unix/Command/_netcat
+++ b/Completion/Unix/Command/_netcat
@@ -6,11 +6,12 @@ if [[ $service = nc ]] && ! _pick_variant netcat=connect nedit -h; then
   return
 fi
 
-if (( ! $+_nc_args )); then
+if (( ! $#_cache_nc_args )); then
+  typeset -ga _cache_nc_args
   local help="$(_call_program options $words[1] -h < /dev/null 2>&1)"
   local -A optionmap
   optionmap=(
-    '*-e prog*' '-e+[program to exec after connect]:prog:_command_names -e'
+    '*-e prog*' '-e+[program to exec after connect]:program:_command_names -e'
      '*-g gateway*' '-g+[source-routing hop point]:gateway:_hosts'
      '*-G num*' '-G[source-routing pointer: 4, 8, 12]'
      '*-i secs*' '-i+[delay interval for lines sent or ports scanned]:delay (secs)'
@@ -28,10 +29,10 @@ if (( ! $+_nc_args )); then
      '*-x*' '-x'
      '*-b*' '-b[allow broadcasts]'
   )
-  _nc_args=($optionmap[(K)"$help"])
+  _cache_nc_args=( $optionmap[(K)"$help"] )
 fi
 
 _arguments -s \
-  "$_nc_args[@]" \
+  "$_cache_nc_args[@]" \
   ':host:_hosts' \
   ':port:_ports'


                 reply	other threads:[~2018-03-24 13:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=7738.1521899133@thecus \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@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).