zsh-workers
 help / color / mirror / code / Atom feed
From: Tanaka Akira <akr@jaist.ac.jp>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: _hosts, _hostports, _telnet and _socket
Date: 12 Sep 1999 12:36:25 +0900	[thread overview]
Message-ID: <rsqemg4kdhi.fsf@crane.jaist.ac.jp> (raw)
In-Reply-To: "Bart Schaefer"'s message of "Sun, 12 Sep 1999 02:20:05 +0000"

In article <990912022006.ZM18909@candle.brasslantern.com>,
  "Bart Schaefer" <schaefer@candle.brasslantern.com> writes:

> This doesn't seem sensible to me at all.  What are you supposed to do,
> repeat every host name for every port to which you might want to telnet?

Yes. Since it is rare case to specify a port, I suppose that it will
not be big problem. But...

> IMO it'd be more useful to leave $hosts as it was and create an AA that
> maps a host name to a space-separated list of ports -- and then maybe
> even to have one such AA for each command that accepts a port number,
> as it's unlikely that one wants to complete the same port numbers for
> e.g. "pine -f ..." as one does for "telnet".

Definitely this is better way to specify the relation between hosts
and ports. So, I modified `_hosts', `_socket' and `_telnet'.

`_telnet' uses AA named `telent_ports' to complete hosts and ports ---
keys for hosts and (word splitted) values for ports.
(If the host completion is failed, `_hosts' is called.)

After applying the patch, you should remove `Completion/User/_hostports'.

Index: Completion/User/_hosts
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_hosts,v
retrieving revision 1.1.1.12
diff -u -F^( -r1.1.1.12 _hosts
--- _hosts	1999/09/12 00:02:40	1.1.1.12
+++ _hosts	1999/09/12 03:34:11
@@ -5,4 +5,4 @@
 : ${(A)hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
 
 _description expl host
-compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" "$expl[@]" - "${hosts[@]%:*}"
+compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" "$expl[@]" - "$hosts[@]"
Index: Completion/User/_socket
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_socket,v
retrieving revision 1.1.1.1
diff -u -F^( -r1.1.1.1 _socket
--- _socket	1999/09/12 00:02:46	1.1.1.1
+++ _socket	1999/09/12 03:34:11
@@ -1,5 +1,12 @@
 #compdef socket
 
+# Parameter used:
+#
+#  socket_ports
+#    The associative array that maps a host name to a space-separated list of 
+#    ports.
+
+
 local state line expl
 typeset -A options
 
@@ -18,17 +25,21 @@
 
 arg1)
   if (( $+options[-s] )); then
-    _message 'port'
+    _message 'port to listen'
   else
     _description expl 'host'
-    _hosts "$expl[@]"
+    compadd "$expl[@]" - ${(k)socket_ports} || _hosts "$expl[@]"
   fi
   ;;
 
 arg2)
   if (( ! $+options[-s] )); then
-    _description expl 'port'
-    _hostports $line[2] "$expl[@]"
+    _description expl 'port to connect'
+    if (( $+socket_ports )); then
+      compadd "$expl[@]" - ${=socket_ports[$line[2]]};
+    else
+      _message 'port to connect';
+    fi
   fi
   ;;
 esac
Index: Completion/User/_telnet
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_telnet,v
retrieving revision 1.1.1.1
diff -u -F^( -r1.1.1.1 _telnet
--- _telnet	1999/09/12 00:02:46	1.1.1.1
+++ _telnet	1999/09/12 03:34:11
@@ -1,5 +1,11 @@
 #compdef telnet
 
+# Parameter used:
+#
+#  telnet_ports
+#    The associative array that maps a host name to a space-separated list of
+#    ports.
+
 _arguments -s \
   -{F,f,x} \
   '-8[allow 8-Bit data]' \
@@ -16,6 +22,6 @@
   '-l+[specify user]:user:' \
   '-n+[specify tracefile]:tracefile:_files' \
   '-r[rlogin like user interface]' \
-  ':host:_hosts' \
-  ':port:{ _hostports $line[2] "$expl[@]" }'
+  ':host:{ compadd "$expl[@]" - ${(k)telnet_ports} || _hosts "$expl[@]" }' \
+  ':port:{ if (( $+telnet_ports )); then compadd "$expl[@]" - ${=telnet_ports[$line[2]]}; else _message "port"; fi }'
 
-- 
Tanaka Akira


  reply	other threads:[~1999-09-12  3:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-12  0:00 Tanaka Akira
1999-09-12  2:20 ` Bart Schaefer
1999-09-12  3:36   ` Tanaka Akira [this message]
1999-09-12 21:25     ` Adam Spiers
1999-09-13 14:06       ` Clint Adams
1999-09-13  9:09     ` Peter Stephenson
1999-09-13 18:20       ` Tanaka Akira
1999-09-14 14:25       ` Clint Adams
1999-09-12 11:26 ` Andrej Borsenkow
1999-09-12 12:26   ` Tanaka Akira
1999-09-17  0:57     ` Tanaka Akira
1999-09-19  0:49       ` Bart Schaefer
1999-09-14  8:34 Sven Wischnowsky
1999-09-15 12:56 ` Tanaka Akira

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=rsqemg4kdhi.fsf@crane.jaist.ac.jp \
    --to=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).