zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: _hosts, _hostports, _telnet and _socket
@ 1999-09-14  8:34 Sven Wischnowsky
  1999-09-15 12:56 ` Tanaka Akira
  0 siblings, 1 reply; 14+ messages in thread
From: Sven Wischnowsky @ 1999-09-14  8:34 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> Hm. As Adam Spiers mentioned, relations between host-port aren't
> special. And I found that `telnet' has `-l' option that specifies
> `user'.  I think the argument of `-l' should be considered when
> completion. So, I prefer more general way to specify such relations.
> 
> I made `_combination' and `_ports' and modified `_socket' and
> `_telnet' to use them.
> 
> # Is there a better name for `_combination'?

At least it is generic enough to go into Base, I think.

> Now `_telnet' can handle following 7 situations.
> 
> ...

This is nice, but a more powerful `_ports' would still be useful for
all the other commands that use port numbers (_rpm, _mount, _nslookup, 
_ssh, _yp). Sometimes looking at the command name to decide which
ports to suggest is enough, but sometimes we might want to look at
other context information (this port forwarding thing in _ssh, for
example). I don't have any ideas about all this, yet, I just thought I 
should mention it.

And while I'm at it: we still need descriptions for the new parameters 
used and the `_combination' and `_regex_arguments' functions in the
docs.

(Btw, did I already ask if someone knows of other parameters used by
the completion system that aren't documented in the config section of
compsys.yo, yet?)

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-14  8:34 PATCH: _hosts, _hostports, _telnet and _socket Sven Wischnowsky
@ 1999-09-15 12:56 ` Tanaka Akira
  0 siblings, 0 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-15 12:56 UTC (permalink / raw)
  To: zsh-workers

In article <199909140834.KAA26818@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> At least it is generic enough to go into Base, I think.

I see.

> And while I'm at it: we still need descriptions for the new parameters 
> used and the `_combination' and `_regex_arguments' functions in the
> docs.

Definitely I think so too.
I'll try to write the descriptions.
(But I'm bit busy in this week.)

> (Btw, did I already ask if someone knows of other parameters used by
> the completion system that aren't documented in the config section of
> compsys.yo, yet?)

Hm. `hosts' is not mentioned except as the example of `_sep_parts'.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-17  0:57     ` Tanaka Akira
@ 1999-09-19  0:49       ` Bart Schaefer
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1999-09-19  0:49 UTC (permalink / raw)
  To: zsh-workers

On Sep 17,  9:57am, Tanaka Akira wrote:
} Subject: Re: PATCH: _hosts, _hostports, _telnet and _socket
}
} In article <rsqvh9g8gf2.fsf@crane.jaist.ac.jp>,
}   Tanaka Akira <akr@jaist.ac.jp> writes:
} 
} > I agree that `telnet' has many variants and `_telnet' should complete
} > only valid options of `telnet' if it is possible.
} 
} Following patch tries this.

A minor improvement ...

Index: Completion/User/_telnet
===================================================================
@@ -9,55 +9,47 @@
 typeset -A options
 
 if (( ! $+_telnet_short )); then
-  local help="$(telnet -\? < /dev/null 2>&1)"
+  local k help="$(telnet -\? < /dev/null 2>&1)"
+  local -A optionmap
+  optionmap=( "[-8]" '-8[allow 8-Bit data]' \
+              "[-E]" '-E[disable an escape character]' \
+              "[-K]" '-K[no automatic login]' \
+              "[-L]" '-L[allow 8-Bit data on output]' \
+              "[-N]" '-N[supress reverse lookup]' \
+              "[-S tos]" '-S+:IP type-of-service:' \
+              "[-X atype]" '-X+:authentication type to disable:' \
+              "[-a]" '-a[attempt automatic login]' \
+              "[-c]" '-c[disable .telnetrc]' \
+              "[-d]" '-d[debug mode]' \
+              "[-e char]" '-e+[specify escape character]:escape character:' \
+              "[-f/" '-f' \
+              "/-F]" '-F' \
+              "[-k realm]" '-k+:realm:' \
+              "[-l user]" '-l+[specify user]:user:->users' \
+              "[-n tracefile]" '-n+[specify tracefile]:tracefile:_files' \
+              "[-r]" '-r[rlogin like user interface]' \
+              "[-s src_addr]" '-s+[set source IP address]:src_addr:' \
+              "[-x]" '-x' \
+              "[-t transcom]" '-t+:transcom:' )
+
   _telnet_short=()
-  [[ "$help" = *"[-8]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-8[allow 8-Bit data]')
-  [[ "$help" = *"[-E]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-E[disable an escape character]')
-  [[ "$help" = *"[-K]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-K[no automatic login]')
-  [[ "$help" = *"[-L]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-L[allow 8-Bit data on output]')
-  [[ "$help" = *"[-N]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-N[supress reverse lookup]')
-  [[ "$help" = *"[-S tos]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-S+:IP type-of-service:')
-  [[ "$help" = *"[-X atype]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-X+:authentication type to disable:')
-  [[ "$help" = *"[-a]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-a[attempt automatic login]')
-  [[ "$help" = *"[-c]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-c[disable .telnetrc]')
-  [[ "$help" = *"[-d]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-d[debug mode]')
-  [[ "$help" = *"[-e char]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-e+[specify escape character]:escape character:')
-  [[ "$help" = *"[-f/-F]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-f' '-F')
-  [[ "$help" = *"[-k realm]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-k+:realm:')
-  [[ "$help" = *"[-l user]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-l+[specify user]:user:->users')
-  [[ "$help" = *"[-n tracefile]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-n+[specify tracefile]:tracefile:_files')
-  [[ "$help" = *"[-r]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-r[rlogin like user interface]')
-  [[ "$help" = *"[-s src_addr]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-s+[set source IP address]:src_addr:')
-  [[ "$help" = *"[-x]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-x')
-  [[ "$help" = *"[-t transcom]"* ]] &&
-    _telnet_short=("$_telnet_short[@]" '-t+:transcom:')
+  for k in ${(k)optionmap}
+  do
+    [[ "$help" = *"$k"* ]] &&
+      _telnet_short=( "$_telnet_short[@]" "$optionmap[$k]" )
+  done
 
   # _arguments cannot handle following three options.
+  optionmap=( "[-noasynch]" '-noasynch' \
+              "[-noasyncnet]" '-noasyncnet' \
+              "[-noasynctty]" '-noasynctty' )
+
   _telnet_long=()
-  [[ "$help" = *"[-noasynch]"* ]] &&
-    _telnet_long=("$_telnet_long[@]" '-noasynch')
-  [[ "$help" = *"[-noasyncnet]"* ]] &&
-    _telnet_long=("$_telnet_long[@]" '-noasyncnet')
-  [[ "$help" = *"[-noasynctty]"* ]] &&
-    _telnet_long=("$_telnet_long[@]" '-noasynctty')
+  for k in ${(k)optionmap}
+  do
+    [[ "$help" = *"$k"* ]] &&
+      _telnet_long=( "$_telnet_long[@]" "$optionmap[$k]" )
+  done
 fi
 
 [[ $#_telnet_long != 0 && (

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12 12:26   ` Tanaka Akira
@ 1999-09-17  0:57     ` Tanaka Akira
  1999-09-19  0:49       ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Tanaka Akira @ 1999-09-17  0:57 UTC (permalink / raw)
  To: zsh-workers

In article <rsqvh9g8gf2.fsf@crane.jaist.ac.jp>,
  Tanaka Akira <akr@jaist.ac.jp> writes:

> I agree that `telnet' has many variants and `_telnet' should complete
> only valid options of `telnet' if it is possible.

Following patch tries this.

Index: Completion/User/_telnet
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_telnet,v
retrieving revision 1.1.1.3
diff -u -F^( -r1.1.1.3 _telnet
--- _telnet	1999/09/13 18:22:22	1.1.1.3
+++ _telnet	1999/09/17 00:50:42
@@ -8,22 +8,68 @@
 local state line expl
 typeset -A options
 
+if (( ! $+_telnet_short )); then
+  local help="$(telnet -\? < /dev/null 2>&1)"
+  _telnet_short=()
+  [[ "$help" = *"[-8]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-8[allow 8-Bit data]')
+  [[ "$help" = *"[-E]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-E[disable an escape character]')
+  [[ "$help" = *"[-K]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-K[no automatic login]')
+  [[ "$help" = *"[-L]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-L[allow 8-Bit data on output]')
+  [[ "$help" = *"[-N]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-N[supress reverse lookup]')
+  [[ "$help" = *"[-S tos]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-S+:IP type-of-service:')
+  [[ "$help" = *"[-X atype]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-X+:authentication type to disable:')
+  [[ "$help" = *"[-a]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-a[attempt automatic login]')
+  [[ "$help" = *"[-c]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-c[disable .telnetrc]')
+  [[ "$help" = *"[-d]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-d[debug mode]')
+  [[ "$help" = *"[-e char]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-e+[specify escape character]:escape character:')
+  [[ "$help" = *"[-f/-F]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-f' '-F')
+  [[ "$help" = *"[-k realm]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-k+:realm:')
+  [[ "$help" = *"[-l user]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-l+[specify user]:user:->users')
+  [[ "$help" = *"[-n tracefile]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-n+[specify tracefile]:tracefile:_files')
+  [[ "$help" = *"[-r]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-r[rlogin like user interface]')
+  [[ "$help" = *"[-s src_addr]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-s+[set source IP address]:src_addr:')
+  [[ "$help" = *"[-x]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-x')
+  [[ "$help" = *"[-t transcom]"* ]] &&
+    _telnet_short=("$_telnet_short[@]" '-t+:transcom:')
+
+  # _arguments cannot handle following three options.
+  _telnet_long=()
+  [[ "$help" = *"[-noasynch]"* ]] &&
+    _telnet_long=("$_telnet_long[@]" '-noasynch')
+  [[ "$help" = *"[-noasyncnet]"* ]] &&
+    _telnet_long=("$_telnet_long[@]" '-noasyncnet')
+  [[ "$help" = *"[-noasynctty]"* ]] &&
+    _telnet_long=("$_telnet_long[@]" '-noasynctty')
+fi
+
+[[ $#_telnet_long != 0 && (
+     -z "$compconfig[option_prefix]" ||
+     "$compconfig[option_prefix]" = *\!${words[1]}* ||
+     "$PREFIX" = [-+]* ) ]] && {
+  _description expl 'option'
+  _describe -o option _telnet_long "$expl[@]"
+}
+
 _arguments -s \
-  -{F,f,x} \
-  '-8[allow 8-Bit data]' \
-  '-E[disable an escape character]' \
-  '-K[no automatic login]' \
-  '-L[allow 8-Bit data on output]' \
-  '-S+:IP type-of-service:' \
-  '-X+:authentication type to disable:' \
-  '-a[attempt automatic login]' \
-  '-c[disable .telnetrc]' \
-  '-d[debug mode]' \
-  '-e+[specify escape character]:escape character:' \
-  '-k+:realm:' \
-  '-l+[specify user]:user:->users' \
-  '-n+[specify tracefile]:tracefile:_files' \
-  '-r[rlogin like user interface]' \
+  "$_telnet_short[@]" \
   ':host:->hosts' \
   ':port:->ports'
 
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-13  9:09     ` Peter Stephenson
  1999-09-13 18:20       ` Tanaka Akira
@ 1999-09-14 14:25       ` Clint Adams
  1 sibling, 0 replies; 14+ messages in thread
From: Clint Adams @ 1999-09-14 14:25 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

> I'd have said there was room for an autoloaded function _ports, which can
> use telnet_ports and then default to something like
>   awk '/^[a-z]/ { print $1 }' /etc/services

It might be more useful to divide based on protocol type if
you know that a particular program is TCP-only.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-13  9:09     ` Peter Stephenson
@ 1999-09-13 18:20       ` Tanaka Akira
  1999-09-14 14:25       ` Clint Adams
  1 sibling, 0 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-13 18:20 UTC (permalink / raw)
  To: Zsh hackers list

In article <199909130909.LAA14546@paris.ifh.de>,
  Peter Stephenson <pws@ifh.de> writes:

> I'd have said there was room for an autoloaded function _ports, which can
> use telnet_ports and then default to something like
>   awk '/^[a-z]/ { print $1 }' /etc/services
> if nothing turns up.  As Bart implied, it might be useful to have it
> index on commands, too:  you could have the convention, say, that
> commands had a trailing * added (quoted, obviously).  Then _ports
> could be called like "_ports <cmd> <host>".  You could make it search
> the assoc array <cmd>_ports, which is sort of what's happening with
> telnet_ports and socket_ports.  In that case indexing on commands is
> perhaps superflous and you could have a special key (e.g. '*') giving
> a default port.

Hm. As Adam Spiers mentioned, relations between host-port aren't
special. And I found that `telnet' has `-l' option that specifies
`user'.  I think the argument of `-l' should be considered when
completion. So, I prefer more general way to specify such relations.

I made `_combination' and `_ports' and modified `_socket' and
`_telnet' to use them.

# Is there a better name for `_combination'?

Now `_telnet' can handle following 7 situations.

% telnet <TAB>		    # completes hosts.
% telnet -l USER <TAB>	    # completes hosts restricted by `USER'.
% telnet HOST <TAB>	    # completes ports restricted by `HOST'.
% telnet -l USER HOST <TAB> # completes ports restricted by `USER' and `HOST'.
% telnet -l <TAB>	    # completes users.
% telnet HOST -l <TAB>	    # completes users restricted by `HOST'.
% telnet HOST PORT -l <TAB> # completes users restricted by `HOST' and `PORT'.

For this, you should define the variable `telnet_hosts_ports_users' as
like:

telnet_hosts_ports_users=(
  host0::
  host1::user1
  host2::user2
  mail-server:{smtp,pop3}:
  news-server:nntp:
  proxy-server:8000:
)

The variable `telnet_hosts_ports_users' is an (normal) array of
strings formed as "host:port:user".

Also, `_telnet' uses `_hosts', `_ports' and `_users' (through
`_combination') if `telnet_hosts_ports_users' cannot match a command
line or it is not defined.

--- /dev/null	Tue Sep 14 02:14:47 1999
+++ Completion/User/_combination	Tue Sep 14 02:30:06 1999
@@ -0,0 +1,85 @@
+#autoload
+
+# Usage:
+#   _combination [-s SEP] VARIABLE KEYi=PATi KEYj=PATj ... KEYm=PATm KEY EXPL...
+#
+#  VARIABLE must be formd as PREFIX_KEY1_..._KEYn.
+#
+# Example: telnet
+#
+#  Assume an user sets the variable `telnet_hosts_ports_users' as:
+#
+#    telnet_hosts_ports_users=(
+#      host0:: host1::user1 host2::user2
+#      mail-server:{smtp,pop3}:
+#      news-server:nntp:
+#      proxy-server:8000:
+#    )
+#
+#  `_telnet completes' hosts as:
+#
+#    _combination telnet_hosts_ports_users \
+#      ${options[-l]:+users=${options[-l]:q}} \
+#      hosts "$expl[@]"
+#
+#  This completes `host1', `host2', `mail-server', `news-server' and
+#  `proxy-server' according to the user given with `-l' if it is exists.
+#  And if it is failed, `_hosts' is called.
+# 
+#  `_telnet' completes ports as:
+#
+#    _combination telnet_hosts_ports_users \
+#      ${options[-l]:+users=${options[-l]:q}} \
+#      hosts="${line[2]:q}" \
+#      ports "$expl[@]"
+#
+#  This completes `smtp', `pop3', `nntp' and `8000' according to the
+#  host argument --- $line[2] and the user option argument if it is
+#  exists. And if it is failed, `_ports' is called.
+#
+#  `_telnet' completes users for an argument of option `-l' as:
+#
+#    _combination telnet_hosts_ports_users \
+#      ${line[2]:+hosts="${line[2]:q}"} \
+#      ${line[3]:+ports="${line[3]:q}"} \
+#      users "$expl[@]"
+#
+#  This completes `user1' and `user2' according to the host argument and
+#  the port argument if they are exist. And if it is failed, `_users' is
+#  called.
+
+local sep var keys pats key tmp
+
+if [[ "$1" = -s ]]; then
+  sep="$2"
+  shift 2
+else
+  sep=:
+fi
+
+var=$1
+shift
+
+keys=( "${(@s:_:)${var#*_}}" )
+pats=( "${(@)keys/*/*}" )
+
+while [[ "$1" = *=* ]]; do
+  pats[$keys[(i)${1%%\=*}]]="${1#*\=}"
+  shift
+done
+
+key="$1"
+shift
+
+if (( ${(P)+${var}} )); then
+  eval "tmp=( \"\${(@M)${var}:#\${(j!$sep!)~pats}}\" )"
+  if (( keys[(i)$key] != 1 )); then
+    eval "tmp=( \${tmp#\${(j!${sep}!)~\${(@)\${(@)keys[2,(r)\$key]}/*/*}}$sep} )"
+  fi
+  tmp=( ${tmp%%$sep*} )
+
+  compadd "$@" - $tmp || { builtin functions _$key >&- && _$key "$@" }
+else
+  builtin functions _$key >&- && _$key "$@"
+fi
+
--- /dev/null	Tue Sep 14 02:14:47 1999
+++ Completion/User/_ports	Tue Sep 14 02:04:51 1999
@@ -0,0 +1,8 @@
+#autoload
+
+local expl
+
+: ${(A)ports:=${${(M)${${(f)"$(</etc/services)"}:#\#*}#*/tcp}%%[ 	]*}}
+
+_description expl port
+compadd "$@" "$expl[@]" - "$ports[@]"
Index: Completion/User/_socket
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_socket,v
retrieving revision 1.1.1.2
diff -u -F^( -r1.1.1.2 _socket
--- _socket	1999/09/12 03:38:21	1.1.1.2
+++ _socket	1999/09/13 17:34:59
@@ -2,11 +2,9 @@
 
 # Parameter used:
 #
-#  socket_ports
-#    The associative array that maps a host name to a space-separated list of 
-#    ports.
+#  socket_hosts_ports
+#    The array that contains paris `host:port'.
 
-
 local state line expl
 typeset -A options
 
@@ -28,18 +26,14 @@
     _message 'port to listen'
   else
     _description expl 'host'
-    compadd "$expl[@]" - ${(k)socket_ports} || _hosts "$expl[@]"
+    _combination socket_hosts_ports hosts "$expl[@]"
   fi
   ;;
 
 arg2)
   if (( ! $+options[-s] )); then
     _description expl 'port to connect'
-    if (( $+socket_ports )); then
-      compadd "$expl[@]" - ${=socket_ports[$line[2]]};
-    else
-      _message 'port to connect';
-    fi
+    _combination socket_hosts_ports hosts="${line[2]:q}" ports "$expl[@]"
   fi
   ;;
 esac
Index: Completion/User/_telnet
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_telnet,v
retrieving revision 1.1.1.2
diff -u -F^( -r1.1.1.2 _telnet
--- _telnet	1999/09/12 03:38:21	1.1.1.2
+++ _telnet	1999/09/13 17:34:59
@@ -2,10 +2,12 @@
 
 # Parameter used:
 #
-#  telnet_ports
-#    The associative array that maps a host name to a space-separated list of
-#    ports.
+#  telnet_hosts_ports_users
+#    The array that contains 3-tuples `host:port:user'.
 
+local state line expl
+typeset -A options
+
 _arguments -s \
   -{F,f,x} \
   '-8[allow 8-Bit data]' \
@@ -19,9 +21,33 @@
   '-d[debug mode]' \
   '-e+[specify escape character]:escape character:' \
   '-k+:realm:' \
-  '-l+[specify user]:user:' \
+  '-l+[specify user]:user:->users' \
   '-n+[specify tracefile]:tracefile:_files' \
   '-r[rlogin like user interface]' \
-  ':host:{ compadd "$expl[@]" - ${(k)telnet_ports} || _hosts "$expl[@]" }' \
-  ':port:{ if (( $+telnet_ports )); then compadd "$expl[@]" - ${=telnet_ports[$line[2]]}; else _message "port"; fi }'
+  ':host:->hosts' \
+  ':port:->ports'
+
+case "$state" in
+hosts)
+  _description expl 'host'
+  _combination telnet_hosts_ports_users \
+    ${options[-l]:+users=${options[-l]:q}} \
+    hosts "$expl[@]"
+  ;;
+
+ports)
+  _description expl 'port'
+  _combination telnet_hosts_ports_users \
+    ${options[-l]:+users=${options[-l]:q}} \
+    hosts="${line[2]:q}" \
+    ports "$expl[@]"
+  ;;
 
+users)
+  _description expl 'user'
+  _combination telnet_hosts_ports_users \
+    ${line[2]:+hosts="${line[2]:q}"} \
+    ${line[3]:+ports="${line[3]:q}"} \
+    users "$expl[@]"
+  ;;
+esac
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12 21:25     ` Adam Spiers
@ 1999-09-13 14:06       ` Clint Adams
  0 siblings, 0 replies; 14+ messages in thread
From: Clint Adams @ 1999-09-13 14:06 UTC (permalink / raw)
  To: zsh-workers

> Cool, this is nice.  It would also be nice to have something similar
> for (user, host) pairs, for use with finger, [ny]talk, ssh etc.

And MUAs.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12  3:36   ` Tanaka Akira
  1999-09-12 21:25     ` Adam Spiers
@ 1999-09-13  9:09     ` Peter Stephenson
  1999-09-13 18:20       ` Tanaka Akira
  1999-09-14 14:25       ` Clint Adams
  1 sibling, 2 replies; 14+ messages in thread
From: Peter Stephenson @ 1999-09-13  9:09 UTC (permalink / raw)
  To: Zsh hackers list

Tanaka Akira wrote:
> `_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.)

Just some random ideas.

I'd have said there was room for an autoloaded function _ports, which can
use telnet_ports and then default to something like
  awk '/^[a-z]/ { print $1 }' /etc/services
if nothing turns up.  As Bart implied, it might be useful to have it
index on commands, too:  you could have the convention, say, that
commands had a trailing * added (quoted, obviously).  Then _ports
could be called like "_ports <cmd> <host>".  You could make it search
the assoc array <cmd>_ports, which is sort of what's happening with
telnet_ports and socket_ports.  In that case indexing on commands is
perhaps superflous and you could have a special key (e.g. '*') giving
a default port.
-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56100 Pisa, Italy


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12  3:36   ` Tanaka Akira
@ 1999-09-12 21:25     ` Adam Spiers
  1999-09-13 14:06       ` Clint Adams
  1999-09-13  9:09     ` Peter Stephenson
  1 sibling, 1 reply; 14+ messages in thread
From: Adam Spiers @ 1999-09-12 21:25 UTC (permalink / raw)
  To: zsh-workers

Tanaka Akira (akr@jaist.ac.jp) wrote:
> Definitely this is better way to specify the relation between hosts
> and ports. So, I modified `_hosts', `_socket' and `_telnet'.

Cool, this is nice.  It would also be nice to have something similar
for (user, host) pairs, for use with finger, [ny]talk, ssh etc.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12 11:26 ` Andrej Borsenkow
@ 1999-09-12 12:26   ` Tanaka Akira
  1999-09-17  0:57     ` Tanaka Akira
  0 siblings, 1 reply; 14+ messages in thread
From: Tanaka Akira @ 1999-09-12 12:26 UTC (permalink / raw)
  To: zsh-workers

In article <000001befd11$ba0b0bb0$21c9ca95@mow.siemens.ru>,
  "Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru> writes:

> Again, the same old question - *what* telnet? Ours does not understand any of
> the options you list (more, than -8, host, port).

`_telnet' is based on 4.4BSD (NetBSD 1.4).
And most of options are supported by Solaris 7 and Debian.
Also, I know that SunOS 4.1.4 doesn't support options at all.

> If Linux telnet is so smart - should this be put in Linux then?

I agree that `telnet' has many variants and `_telnet' should complete
only valid options of `telnet' if it is possible.

Extracting existence of options from the help text is better way. But
the help text of telnet is not suitable for `_arguments'.

Hm. Maybe `_arguments' should take an argument for a function to parse
a help text.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12  0:00 Tanaka Akira
  1999-09-12  2:20 ` Bart Schaefer
@ 1999-09-12 11:26 ` Andrej Borsenkow
  1999-09-12 12:26   ` Tanaka Akira
  1 sibling, 1 reply; 14+ messages in thread
From: Andrej Borsenkow @ 1999-09-12 11:26 UTC (permalink / raw)
  To: Tanaka Akira, zsh-workers

>
> I made `_telnet' and `_socket'. They may complete port number and
> names depend on a host argument.
>

Again, the same old question - *what* telnet? Ours does not understand any of
the options you list (more, than -8, host, port).

If Linux telnet is so smart - should this be put in Linux then?


/andrej


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12  2:20 ` Bart Schaefer
@ 1999-09-12  3:36   ` Tanaka Akira
  1999-09-12 21:25     ` Adam Spiers
  1999-09-13  9:09     ` Peter Stephenson
  0 siblings, 2 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-12  3:36 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: PATCH: _hosts, _hostports, _telnet and _socket
  1999-09-12  0:00 Tanaka Akira
@ 1999-09-12  2:20 ` Bart Schaefer
  1999-09-12  3:36   ` Tanaka Akira
  1999-09-12 11:26 ` Andrej Borsenkow
  1 sibling, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 1999-09-12  2:20 UTC (permalink / raw)
  To: zsh-workers

On Sep 12,  9:00am, Tanaka Akira wrote:
} Subject: PATCH: _hosts, _hostports, _telnet and _socket
}
} So I extended the format of the variable `hosts' to be able to contain
} port numbers and names as:
} 
} hosts=(... host:port ...)

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?

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".

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* PATCH: _hosts, _hostports, _telnet and _socket
@ 1999-09-12  0:00 Tanaka Akira
  1999-09-12  2:20 ` Bart Schaefer
  1999-09-12 11:26 ` Andrej Borsenkow
  0 siblings, 2 replies; 14+ messages in thread
From: Tanaka Akira @ 1999-09-12  0:00 UTC (permalink / raw)
  To: zsh-workers

I made `_telnet' and `_socket'. They may complete port number and
names depend on a host argument.

So I extended the format of the variable `hosts' to be able to contain
port numbers and names as:

hosts=(... host:port ...)

For that purpose, I modified `_hosts' to handle this format and made
`_hostports' to complete port numbers and names depend on a host.

Index: Completion/User/_hosts
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_hosts,v
retrieving revision 1.1.1.11
diff -u -F^( -r1.1.1.11 _hosts
--- _hosts	1999/09/06 18:36:15	1.1.1.11
+++ _hosts	1999/09/11 23:42:55
@@ -1,8 +1,8 @@
-#compdef ftp ncftp ping rwho rup xping traceroute telnet
+#compdef ftp ncftp ping rwho rup xping traceroute
 
 local expl
 
 : ${(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[@]%:*}"
--- /dev/null	Sun Sep 12 07:58:58 1999
+++ Completion/User/_hostports	Sun Sep 12 08:36:42 1999
@@ -0,0 +1,9 @@
+#autoload
+
+# Usage: _hostport host
+
+local host="$1"
+shift
+
+compadd "$@" - ${${(M)hosts\:#$host\:*}#*\:}
+
--- /dev/null	Sun Sep 12 07:58:58 1999
+++ Completion/User/_telnet	Sun Sep 12 08:40:05 1999
@@ -0,0 +1,21 @@
+#compdef telnet
+
+_arguments -s \
+  -{F,f,x} \
+  '-8[allow 8-Bit data]' \
+  '-E[disable an escape character]' \
+  '-K[no automatic login]' \
+  '-L[allow 8-Bit data on output]' \
+  '-S+:IP type-of-service:' \
+  '-X+:authentication type to disable:' \
+  '-a[attempt automatic login]' \
+  '-c[disable .telnetrc]' \
+  '-d[debug mode]' \
+  '-e+[specify escape character]:escape character:' \
+  '-k+:realm:' \
+  '-l+[specify user]:user:' \
+  '-n+[specify tracefile]:tracefile:_files' \
+  '-r[rlogin like user interface]' \
+  ':host:_hosts' \
+  ':port:{ _hostports $line[2] "$expl[@]" }'
+
--- /dev/null	Sun Sep 12 07:58:58 1999
+++ Completion/User/_socket	Sun Sep 12 08:40:14 1999
@@ -0,0 +1,34 @@
+#compdef socket
+
+local state line expl
+typeset -A options
+
+_arguments -s \
+  -{b,c,f,q,r,v,w} \
+  -{s,l} \
+  '-p:command:->command' \
+  ':arg1:->arg1' \
+  ':arg2:->arg2'
+
+case "$state" in
+command)
+  compset -q
+  _normal
+  ;;
+
+arg1)
+  if (( $+options[-s] )); then
+    _message 'port'
+  else
+    _description expl 'host'
+    _hosts "$expl[@]"
+  fi
+  ;;
+
+arg2)
+  if (( ! $+options[-s] )); then
+    _description expl 'port'
+    _hostports $line[2] "$expl[@]"
+  fi
+  ;;
+esac
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~1999-09-19  0:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-14  8:34 PATCH: _hosts, _hostports, _telnet and _socket Sven Wischnowsky
1999-09-15 12:56 ` Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
1999-09-12  0:00 Tanaka Akira
1999-09-12  2:20 ` Bart Schaefer
1999-09-12  3:36   ` Tanaka Akira
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

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).