Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: _hosts, _hostports, _telnet and _socket



In article <990912022006.ZM18909@xxxxxxxxxxxxxxxxxxxxxxx>,
  "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author