zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: improvement to user@host completions
@ 1999-10-11 11:22 Sven Wischnowsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-10-11 11:22 UTC (permalink / raw)
  To: zsh-workers


Adam Spiers wrote:

> There's also the `Completion System Configuration' section of the info
> pages.  Is it a deliberate choice that descriptions of most of the
> standard completion functions (e.g. _dirs, _users, _groups) are
> missing from the info pages?  If not, should they go in the `Utility
> Functions' section, or maybe in a new section immediately following it?

Deliberate in the sense that noone (at least not me) took the time to
write that. *But* I already wished we had it, too. So, if you offer to 
write them: yes, please ;-)

I'd vote for a separate section because the function in `Utility
Functions' don't generate the matches themselves, they are told what
should be added, whereas functions like `_users' decide that for
themselves.

(This may also be a bit of a banana problem: `_x_colors' and friends?)

> Out of curiosity, has anyone any ideas on what the official release
> plans are for the near future?  3.1.7 soon, or not?  Are there any
> more big plans for 3.2?

At least I am only still dreaming of a generic package system (to
replace the ad hoc compinit and friends) and of a cleanup for the
keymap stuff.

Bye
 Sven



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


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

* Re: PATCH: improvement to user@host completions
  1999-09-26 14:17 Adam Spiers
  1999-09-26 15:02 ` Peter Stephenson
@ 1999-09-27  7:54 ` Tanaka Akira
  1 sibling, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 1999-09-27  7:54 UTC (permalink / raw)
  To: zsh workers mailing list

In article <19990926151723.F1246@thelonious.new.ox.ac.uk>,
  Adam Spiers <adam@thelonious.new.ox.ac.uk> writes:

> +++ _other_accounts	Sun Sep 26 12:56:46 1999
...
> +_user@host

Z(2):akr@is27e1u11% finger <TAB>_other_accounts: command not found: _user@host [14]
_other_accounts: command not found: _user@host [14]
_other_accounts: command not found: _user@host [14]

Hm. `_user@host' is forgotten.
-- 
Tanaka Akira


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

* Re: PATCH: improvement to user@host completions
  1999-09-26 15:02 ` Peter Stephenson
  1999-09-26 16:57   ` Bart Schaefer
@ 1999-09-26 23:28   ` Adam Spiers
  1 sibling, 0 replies; 6+ messages in thread
From: Adam Spiers @ 1999-09-26 23:28 UTC (permalink / raw)
  To: zsh workers mailing list

Peter Stephenson (pws@ibmth.df.unipi.it) wrote:
> Adam Spiers wrote:
> > This patch harnesses the power of Tanaka's _combination in _rlogin, _ssh
> > and other functions.
> 
> This is an excellent idea, but it could do with some documentation.

Yes, sorry; I've been a bit slack about documentation :-) Problem is,
I'm spending way more time on just the coding than I should be, let
alone anything else ...  Documentation for these will follow when the
appropriate tuits present themselves, and I'll document new stuff as
it comes, which is the best way of doing things anyway.

> Currently that just means comments in the appropriate functions.  (Not all
> functions have them, of course, but here it's crucial that users know
> they're supposed to set some variables.)

There's also the `Completion System Configuration' section of the info
pages.  Is it a deliberate choice that descriptions of most of the
standard completion functions (e.g. _dirs, _users, _groups) are
missing from the info pages?  If not, should they go in the `Utility
Functions' section, or maybe in a new section immediately following it?

> Ideally, the functions _ssh_users
> and _ssh_hosts should be tested for existence before they're defined
> so that users can define their own.

Nice idea.  I'll try to get around to that too.

> There were some typos which I've fixed.

<groan of embarrassment>  I really need to stop this late night coding :-(

> However (long digresion), in the long run I'm hoping for some
> context-sensitive help.  Something like _description would be used to add
> it.  It would give a message something like this (I've assumed my
> suggestion for tags and locators, but it doesn't have to depend on that at
> all):
> 
>   % tar xvzf ^X^H
>   Current completion context is _tar->tar-archive.
>   _tar performs completion for the tar command, including GNU tar extension.
>   Possible subcontexts are:
>     option, tarfile, content, file
>   Subcontext tar-archive completes a tar archive.  By default this
>   is a file ending in *.tar, although this can be modified by the GNU -z
>   option to search for *.tar.gz.
>   Tags used:
>     glob:     use specific pattern to find a file
>     path:     directory path to a file
>     anyfile:  use any file as default if glob tag fails.
> 
> or in this case
> 
>   % ssh ^X^H
>   Current completion context is _ssh->userhost.
>   _ssh performs completion for ssh and related commands such as scp.
>   Possible subcontexts are:
>     option forward command userhost
>   Subcontext userhost completes either hostnames, or user@host pairs.
>   For this to work best the arrays my_accounts and other_accounts
>   should be set; each contains entries in the form user:[host] where
>   host defaults to the current host, or {user1,user2}:host for
>   multiple users on the same host.  You may also set <cmd>_accounts
>   for each specific <cmd> such as ssh.
>   Tags used:
>     userat:  complete username for the form user@host
>     host:    complete an Internet hostname.
> 
> I've simplified this because in fact there is a separate function
> _tar_archive, and I haven't worked out how that fits in to this scheme.  To
> remind you: my idea about tags (and Sven was no doubt thinking along
> similar lines) was that they could allow you to set priorities for
> completions, e.g. you could say you only wanted user@ to be completed if
> all the hosts failed.  Then you could extend the tags to set priorities for
> my_accounts and other_accounts.  There could also be an option so that
> typing ^D multiple times toggles between showing the completion list and
> showing the context-sensitive help.  This is all Zukunftsmusik.

This is all very sweet, albeit somewhat ambitious!  I look forward to
the day it's implemented.

Out of curiosity, has anyone any ideas on what the official release
plans are for the near future?  3.1.7 soon, or not?  Are there any
more big plans for 3.2?


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

* Re: PATCH: improvement to user@host completions
  1999-09-26 15:02 ` Peter Stephenson
@ 1999-09-26 16:57   ` Bart Schaefer
  1999-09-26 23:28   ` Adam Spiers
  1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 1999-09-26 16:57 UTC (permalink / raw)
  To: zsh workers mailing list

On Sep 26,  5:02pm, Peter Stephenson wrote:
} Subject: Re: PATCH: improvement to user@host completions
}
} This is an excellent idea, but it could do with some documentation.
} Currently that just means comments in the appropriate functions.
} 
} However (long digresion), in the long run I'm hoping for some
} context-sensitive help.  Something like _description would be used to add
} it.

I faced a similar problem when I was working on Z-Mail:  Functions written
in the "Z-Script" language could be attached to GUI elements like buttons
or menus; the Motif UI spec says that if the mouse is over such an element
when the user presses F1, he's supposed to get context-sensitive help.

The Z-Mail builtins all accept -? to display a usage message, so the most
obvious thing to do for context help was to run the command with -? and
display the output in a help dialog.  The -? argument was implemented by
intercepting it at the equivalent of zsh's exec.c:execcmd() and branching
into the help code, which did a lookup on the command name.  It was simple
to do the same for user functions.

So then we needed a way to get the help text for the function into the
help system, without actually running the function.  So we implemented a
special comment syntax:  If the function definition began with a block
comment, and that comment contained a line beginning with #%, then the
rest of the comment up to the next #% line was the help text.  This got
stashed in the help system when the function was parsed.  Any function
that did not have such a comment got a default "FOO is a user-defined
function ..." message.

This scheme had the additional good side-effect of encouraging people to
put readable descriptions of their functions at the top of each.

Of course this won't quite work for the completion system because of the
way _main_complete et al select other functions to do the actual work.  A
possible approach might be to set a global flag that means "we're getting
help, not performing actual completion" and then run the functions for the
current context as usual -- but whenever a match would be added, the help
text (previously collected) for that function (or the nearest surrounding
one) gets added instead.

This would omit (fail to emit) the help text for any function in which no
completion is currently found, but that may not be a bad thing.  Are there
any interesting cases in which a completion function is called if and only
if some previous function DID find some matches?

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


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

* Re: PATCH: improvement to user@host completions
  1999-09-26 14:17 Adam Spiers
@ 1999-09-26 15:02 ` Peter Stephenson
  1999-09-26 16:57   ` Bart Schaefer
  1999-09-26 23:28   ` Adam Spiers
  1999-09-27  7:54 ` Tanaka Akira
  1 sibling, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 1999-09-26 15:02 UTC (permalink / raw)
  To: zsh workers mailing list

Adam Spiers wrote:
> This patch harnesses the power of Tanaka's _combination in _rlogin, _ssh
> and other functions.
> 
> The user should put something similar to the following in his .zshrc:
>
> ...
> 
> and then a whole family of commands will then intelligently complete
> (user, host) pairs, in both `-l user host' (where appropriate) and
> `user@host' style.  Currently the rlogin and ssh family are affected,
> and also ytalk and finger.

This is an excellent idea, but it could do with some documentation.
Currently that just means comments in the appropriate functions.  (Not all
functions have them, of course, but here it's crucial that users know
they're supposed to set some variables.)  Ideally, the functions _ssh_users
and _ssh_hosts should be tested for existence before they're defined
so that users can define their own.  There were some typos which I've
fixed.

However (long digresion), in the long run I'm hoping for some
context-sensitive help.  Something like _description would be used to add
it.  It would give a message something like this (I've assumed my
suggestion for tags and locators, but it doesn't have to depend on that at
all):

  % tar xvzf ^X^H
  Current completion context is _tar->tar-archive.
  _tar performs completion for the tar command, including GNU tar extension.
  Possible subcontexts are:
    option, tarfile, content, file
  Subcontext tar-archive completes a tar archive.  By default this
  is a file ending in *.tar, although this can be modified by the GNU -z
  option to search for *.tar.gz.
  Tags used:
    glob:     use specific pattern to find a file
    path:     directory path to a file
    anyfile:  use any file as default if glob tag fails.

or in this case

  % ssh ^X^H
  Current completion context is _ssh->userhost.
  _ssh performs completion for ssh and related commands such as scp.
  Possible subcontexts are:
    option forward command userhost
  Subcontext userhost completes either hostnames, or user@host pairs.
  For this to work best the arrays my_accounts and other_accounts
  should be set; each contains entries in the form user:[host] where
  host defaults to the current host, or {user1,user2}:host for
  multiple users on the same host.  You may also set <cmd>_accounts
  for each specific <cmd> such as ssh.
  Tags used:
    userat:  complete username for the form user@host
    host:    complete an Internet hostname.

I've simplified this because in fact there is a separate function
_tar_archive, and I haven't worked out how that fits in to this scheme.  To
remind you: my idea about tags (and Sven was no doubt thinking along
similar lines) was that they could allow you to set priorities for
completions, e.g. you could say you only wanted user@ to be completed if
all the hosts failed.  Then you could extend the tags to set priorities for
my_accounts and other_accounts.  There could also be an option so that
typing ^D multiple times toggles between showing the completion list and
showing the context-sensitive help.  This is all Zukunftsmusik.

> P.S. Why does cvs diff not put the full path in the +++ line for newly
> added files?  And why doesn't patch understand `Index:' ?

Did you call cvs diff from the top level directory?  I think patch only
recognises `Index:' on the line immediately before the hunk it refers to.
I don't know CVS well enough to tell you why it didn't happen.

--- Completion/User/_users_on.c2	Sun Sep 26 15:47:42 1999
+++ Completion/User/_users_on	Sun Sep 26 16:33:01 1999
@@ -1,9 +1,9 @@
-#autoload write
+#compdef write
 
 local expl
 
 if which users >/dev/null; then
-  _description expl users logged on
+  _description expl 'users logged on'
   compadd "$@" "$expl[@]" - $(users) && return 0
 else
   # Other methods of finding out users logged on should be added here

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* PATCH: improvement to user@host completions
@ 1999-09-26 14:17 Adam Spiers
  1999-09-26 15:02 ` Peter Stephenson
  1999-09-27  7:54 ` Tanaka Akira
  0 siblings, 2 replies; 6+ messages in thread
From: Adam Spiers @ 1999-09-26 14:17 UTC (permalink / raw)
  To: zsh workers mailing list

This patch harnesses the power of Tanaka's _combination in _rlogin, _ssh
and other functions.

The user should put something similar to the following in his .zshrc:

# All my accounts:
my_accounts=(
    joe:
    {joe,root}:mymachine.com
    jbloggs:myothermachine.com
)

# Other people's accounts:
other_accounts=(
    bob:
    {fred,root}:hismachine.com
    vera:hermachine.com
)

and then a whole family of commands will then intelligently complete
(user, host) pairs, in both `-l user host' (where appropriate) and
`user@host' style.  Currently the rlogin and ssh family are affected,
and also ytalk and finger.

If the user wishs to override this completion behaviour for any of
these commands, he can set `FOO_accounts' to a new array, where FOO is
the command in question.

The patch also includes a _users_on completion function for completing
users currently logged on; `write' will complete using this.

P.S. Why does cvs diff not put the full path in the +++ line for newly
added files?  And why doesn't patch understand `Index:' ?


Index: Completion/User/_my_accounts
===================================================================
RCS file: _my_accounts
diff -N _my_accounts
--- /dev/null	Tue May  5 21:32:27 1998
+++ _my_accounts	Sun Sep 26 12:58:55 1999
@@ -0,0 +1,14 @@
+#autoload
+
+local expl nm="$compstate[nmatches]"
+local accounts_users_hosts
+
+local varname="$words[1]_accounts"
+
+if [[ ${(P)+varname} -eq 1 ]]; then
+  accounts_users_hosts=( ${(P)varname} )
+else
+  accounts_users_hosts=( $my_accounts )
+fi
+
+_user@host
Index: Completion/User/_other_accounts
===================================================================
RCS file: _other_accounts
diff -N _other_accounts
--- /dev/null	Tue May  5 21:32:27 1998
+++ _other_accounts	Sun Sep 26 12:56:46 1999
@@ -0,0 +1,14 @@
+#compdef ytalk finger
+
+local expl nm="$compstate[nmatches]"
+local accounts_users_hosts
+
+local varname="$words[1]_accounts"
+
+if [[ ${(P)+varname} -eq 1 ]]; then
+  accounts_users_hosts=( ${(P)varname} )
+else
+  accounts_users_hosts=( $other_accounts )
+fi
+
+_user@host
Index: Completion/User/_rlogin
===================================================================
RCS file: /usr/local/cvsroot/zsh/Completion/User/_rlogin,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 _rlogin
--- Completion/User/_rlogin	1999/09/21 12:15:43	1.1.1.3
+++ Completion/User/_rlogin	1999/09/26 12:57:21
@@ -1,51 +1,82 @@
 #compdef rlogin rsh remsh rcp
 
-case "$words[1]" in
-rlogin)
-  _arguments -s \
-    '-8[allow 8-Bit data]' \
-    '-e-[specify escape character]:escape character:' \
-    '-l[specify login user name]:login as:_users' \
-    ':remote host name:_hosts'
-  ;;
-rsh|remsh)
-  local state line ret=1
-  typeset -A options
-
-  _arguments -s \
-    '-n[ignore stdin]' \
-    '-l[specify login user name]:login as:_users' \
-    ':remote host name:_hosts' \
-    ':command: _command_names -e' \
-    '*::command:->command' && ret=0
-
-  if [[ -n "$state" ]]; then
-    shift 1 words
-    (( CURRENT-- ))
-    _normal && ret=0
+_rlogin () {
+  local accounts_users_hosts
+
+  local varname="$words[1]_accounts"
+
+  if (( ${(P)+varname} )); then
+    accounts_users_hosts=( ${(P)varname} )
+  else
+    accounts_users_hosts=( $my_accounts )
   fi
-  return ret
-  ;;
-rcp)
-  local state line ret=1
-  typeset -A options
-
-  _arguments -s \
-    '-p[preserve modification times]' \
-    '-r[recursively copy directories]' \
-    '*:files:->files' && ret=0
-
-  if [[ -n "$state" ]]; then
-    if compset -P '*:'; then
-      _files && ret=0
-    elif compset -P '*@'; then
-      _hosts -S: && ret=0
-    else
-      _files && ret=0
-      _hosts -S: && ret=0
-      _users -S@ && ret=0
+
+  case "$words[1]" in
+  rlogin)
+    _arguments -s \
+      '-8[allow 8-Bit data]' \
+      '-e-[specify escape character]:escape character:' \
+      '-l[specify login user name]:login as:_rlogin_users' \
+      ':remote host name:_rlogin_hosts'
+    ;;
+  rsh|remsh)
+    local state line ret=1
+    typeset -A options
+
+    _arguments -s \
+      '-n[ignore stdin]' \
+      '-l[specify login user name]:login as:_rlogin_users' \
+      ':remote host name:_rlogin_hosts' \
+      ':command: _command_names -e' \
+      '*::command:->command' && ret=0
+
+    if [[ -n "$state" ]]; then
+      shift 1 words
+      (( CURRENT-- ))
+      _normal && ret=0
+    fi
+    return ret
+    ;;
+  rcp)
+    local state line ret=1
+    typeset -A options
+
+    _arguments -s \
+      '-p[preserve modification times]' \
+      '-r[recursively copy directories]' \
+      '*:files:->files' && ret=0
+
+    if [[ -n "$state" ]]; then
+      if compset -P '*:'; then
+	_files && ret=0
+      elif compset -P '*@'; then
+	_rlogin_hosts -S: -q && ret=0
+      else
+	_files && ret=0
+	_rlogin_all_hosts -S: -q && ret=0
+	_rlogin_users -S@ -q && ret=0
+      fi
     fi
+    return ret
+    ;;    
+  esac
+}
+
+_rlogin_users () {
+  _combination accounts_users_hosts users "$@"
+}
+
+_rlogin_hosts () {
+  if [[ "$IPREFIX" == *@ ]]; then
+    _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@"
+  else
+    _combination accounts_users_hosts \
+      ${options[-l]:+"users=${options[-l]:q}"} hosts "$@"
   fi
-  return ret
-  ;;    
-esac
+}
+
+_rlogin_all_hosts () {
+  _combination accounts_users_hosts hosts "$@"
+}
+
+_rlogin "$@"
Index: Completion/User/_ssh
===================================================================
RCS file: /usr/local/cvsroot/zsh/Completion/User/_ssh,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 _ssh
--- Completion/User/_ssh	1999/09/21 12:15:43	1.1.1.1
+++ Completion/User/_ssh	1999/09/26 13:47:56
@@ -1,208 +1,237 @@
 #compdef ssh slogin scp ssh-add ssh-agent ssh-keygen
 
-local state lstate line ret=1 expl args
-typeset -A options
+_ssh () {
+  local state lstate line ret=1 expl args
+  typeset -A options
+
+  local accounts_users_hosts
+
+  local varname="$words[1]_accounts"
+
+  if (( ${(P)+varname} )); then
+    accounts_users_hosts=( ${(P)varname} )
+  else
+    accounts_users_hosts=( $my_accounts )
+  fi
 
-args=()
+  args=()
 
-# ssh-opt is a pseudo-command used to complete ssh options for `scp -o'.
+  # ssh-opt is a pseudo-command used to complete ssh options for `scp -o'.
 
-case "$words[1]" in
-ssh|slogin)
-  args=(
-    ':remote host name:->userhost'
-    ':command: _command_names -e'
-    '*::args:->command'
-  )
-  ;&
-ssh-opt)
-  _arguments -s \
-    '-a[disable forwarding of authentication agent connection]' \
-    '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
-    '-e[set escape character]:escape character (or `none'"'"'):' \
-    '(-n)-f[go to background]' \
-    '-i[select identity file]:SSH identity file:_files' \
-    '-k[disable forwarding of kerberos tickets]' \
-    '-l[specify login name]:login name:_users' \
-    '-n[redirect stdin from /dev/null]' \
-    '*-o[specify extra options]:option string:->option' \
-    '-p[specify port on remote host]:port number on remote host:' \
-    '-q[quiet operation]' \
-    '-P[use non priviledged port]' \
-    '-t[force pseudo-tty allocation]' \
-    '-v[verbose mode]' \
-    '-V[show version number]' \
-    '-x[disable X11 forwarding]' \
-    '-C[compress all data]' \
-    '-L[specify local port forwarding]:local port forwarding:->forward' \
-    '-R[specify remote port forwarding]:remote port forwarding:->forward' \
-    "$args[@]" && ret=0
-
-  while [[ -n "$state" ]]; do
-    lstate="$state"
-    state=''
-
-    case "$lstate" in
-    option)
-      if compset -P '*[= ]'; then
-        case "$IPREFIX" in
-        *(#i)(batchmode|compression|fallbacktorsh|forward(agent|x11)|keepalive|passwordauthentication|rhosts(|rsa)authentication|rsaauthentication|usersh|kerberos(authetication|tgtparsing)|usepriviledgedport)*)
-          compadd yes no && ret=0
-  	;;
-        *(#i)cipher*)
-          _description expl 'encryption cipher'
-          compadd "$expl[@]" idea des 3des blowfish arcfour tss none && ret=0
-          ;;
-        *(#i)globalknownhostsfile*)
-          _description expl 'global file with known hosts'
-          _files "$expl[@]" && ret=0
-          ;;
-        *(#i)hostname*)
-          _description expl 'real host name to log into'
-          _hosts "$expl[@]" && ret=0
-          ;;
-        *(#i)identityfile*)
-          _description expl 'SSH identity file'
-          _files "$expl[@]" && ret=0
-          ;;
-        *(#i)(local|remote)forward*)
-          state=forward
-          ;;
-        *(#i)proxycommand*)
-          compset -q
-  	  shift 1 words
-	  (( CURRENT-- ))
-          _normal && ret=0
-          ;;
-        *(#i)stricthostkeychecking*)
-          compadd yes no ask
-          ;;
-        *(#i)userknownhostsfile*)
-          _description expl 'user file with known hosts'
-          _files "$expl[@]" && ret=0
-          ;;
-        *(#i)user*)
-          _description expl 'user to log in as'
-          _users "$expl[@]" && ret=0
-          ;;
-        *(#i)xauthlocation*)
-          _description expl 'xauth program'
-          _files "$expl[@]" -g '*(*)' && ret=0
-          ;;
-        esac
-      else
-        _description expl 'configure file option'
-        compadd "$expl[@]" -M 'm:{a-z}={A-Z}' -S '=' - \
-                BatchMode ClearAllForwardings Cipher Compression CompressionLevel \
-	        Host ConnectionAttempts EscapeChar FallBackToRsh ForwardAgent \
-	        ForwardX11 GlobalKnownHostsFile HostName IdentityFile KeepAlive \
-	        KerberosAuthentication KerberosTgtPassing LocalForward \
-	        NumberOfPasswordPrompts PasswordAuthentication Port ProxyCommand \
-	        RemoteForward RhostsAuthentication RhostsRSAAuthentication \
-	        RSAAuthentication StrictHostKeyChecking TISAuthentication \
-	        UsePriviledgedPort User UserKnownHostsFile UseRsh \
-                XAuthLocation && ret=0
-      fi
-      ;;
-    forward)
-      if compset -P 1 '*:'; then
-        if compset -P '*:'; then
-          _message 'port number'
+  case "$words[1]" in
+  ssh|slogin)
+    args=(
+      ':remote host name:->userhost'
+      ':command: _command_names -e'
+      '*::args:->command'
+    )
+    ;&
+  ssh-opt)
+    _arguments -s \
+      '-a[disable forwarding of authentication agent connection]' \
+      '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
+      '-e[set escape character]:escape character (or `none'"'"'):' \
+      '(-n)-f[go to background]' \
+      '-i[select identity file]:SSH identity file:_files' \
+      '-k[disable forwarding of kerberos tickets]' \
+      '-l[specify login name]:login name:_ssh_users' \
+      '-n[redirect stdin from /dev/null]' \
+      '*-o[specify extra options]:option string:->option' \
+      '-p[specify port on remote host]:port number on remote host:' \
+      '-q[quiet operation]' \
+      '-P[use non priviledged port]' \
+      '-t[force pseudo-tty allocation]' \
+      '-v[verbose mode]' \
+      '-V[show version number]' \
+      '-x[disable X11 forwarding]' \
+      '-C[compress all data]' \
+      '-L[specify local port forwarding]:local port forwarding:->forward' \
+      '-R[specify remote port forwarding]:remote port forwarding:->forward' \
+      "$args[@]" && ret=0
+
+    while [[ -n "$state" ]]; do
+      lstate="$state"
+      state=''
+
+      case "$lstate" in
+      option)
+        if compset -P '*[= ]'; then
+          case "$IPREFIX" in
+          *(#i)(batchmode|compression|fallbacktorsh|forward(agent|x11)|keepalive|passwordauthentication|rhosts(|rsa)authentication|rsaauthentication|usersh|kerberos(authetication|tgtparsing)|usepriviledgedport)*)
+            compadd yes no && ret=0
+            ;;
+          *(#i)cipher*)
+            _description expl 'encryption cipher'
+            compadd "$expl[@]" idea des 3des blowfish arcfour tss none && ret=0
+            ;;
+          *(#i)globalknownhostsfile*)
+            _description expl 'global file with known hosts'
+            _files "$expl[@]" && ret=0
+            ;;
+          *(#i)hostname*)
+            _description expl 'real host name to log into'
+            _ssh_hosts "$expl[@]" && ret=0
+            ;;
+          *(#i)identityfile*)
+            _description expl 'SSH identity file'
+            _files "$expl[@]" && ret=0
+            ;;
+          *(#i)(local|remote)forward*)
+            state=forward
+            ;;
+          *(#i)proxycommand*)
+            compset -q
+            shift 1 words
+            (( CURRENT-- ))
+            _normal && ret=0
+            ;;
+          *(#i)stricthostkeychecking*)
+            compadd yes no ask
+            ;;
+          *(#i)userknownhostsfile*)
+            _description expl 'user file with known hosts'
+            _files "$expl[@]" && ret=0
+            ;;
+          *(#i)user*)
+            _description expl 'user to log in as'
+            _ssh_users "$expl[@]" && ret=0
+            ;;
+          *(#i)xauthlocation*)
+            _description expl 'xauth program'
+            _files "$expl[@]" -g '*(*)' && ret=0
+            ;;
+          esac
         else
-          _hosts -S:
+          _description expl 'configure file option'
+          compadd "$expl[@]" -M 'm:{a-z}={A-Z}' -S '=' - \
+              BatchMode ClearAllForwardings Cipher Compression \
+              CompressionLevel Host ConnectionAttempts EscapeChar \
+              FallBackToRsh ForwardAgent ForwardX11 \
+              GlobalKnownHostsFile HostName IdentityFile KeepAlive \
+              KerberosAuthentication KerberosTgtPassing LocalForward \
+              NumberOfPasswordPrompts PasswordAuthentication Port \
+              ProxyCommand RemoteForward RhostsAuthentication \
+              RhostsRSAAuthentication RSAAuthentication \
+              StrictHostKeyChecking TISAuthentication \
+              UsePriviledgedPort User UserKnownHostsFile UseRsh \
+              XAuthLocation \
+            && ret=0
         fi
-      else
-        _message 'listen-port number'
-      fi
-      return
-      ;;
-    command)
-      shift 1 words
-      (( CURRENT-- ))
-      _normal
-      return
-      ;;
-    userhost)
-      if compset -P '*@'; then
-        _description expl 'remote host name'
-        _hosts "$expl[@]"
-	return
-      else
-        _description expl 'remote host name'
-        _hosts "$expl[@]" && ret=0
-	if (( ! $+options[-l] )); then
-	  _description expl 'login name'
-	  _users "$expl[@]" -S@ && ret=0
+        ;;
+      forward)
+        if compset -P 1 '*:'; then
+          if compset -P '*:'; then
+            _message 'port number'
+          else
+            _ssh_hosts -S: -q
+          fi
+        else
+          _message 'listen-port number'
         fi
-      fi
-      ;;
-    esac
+        return
+        ;;
+      command)
+        shift 1 words
+        (( CURRENT-- ))
+        _normal
+        return
+        ;;
+      userhost)
+        if compset -P '*@'; then
+          _description expl 'remote host name'
+          _ssh_hosts "$expl[@]" && ret=0
+        else
+          _description expl 'remote host name'
+          _ssh_hosts "$expl[@]" && ret=0
+          if (( ! $+options[-l] )); then
+            _description expl 'login name'
+            _ssh_users "$expl[@]" -S@ -q && ret=0
+          fi
+        fi
+        ;;
+      esac
 
-    break;
-  done
+      break;
+    done
 
-  return ret
-  ;;
-scp)
-  _arguments -s \
-    '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
-    '-P[specify port on remote host]:port number on remote host:' \
-    '-i[select identity file]:SSH identity file:_files' \
-    '-S[specify path to ssh]:path to ssh:_files -g \*\(\*\)' \
-    '-o[give SSH options]:options:->options' \
-    '-p[preserve modification times]' \
-    '-r[recursively copy directories]' \
-    '-v[verbose mode]' \
-    '-B[batch mode]' \
-    '-C[compress data]' \
-    '*:file:->file' && ret=0
-
-  if [[ "$state" = options ]]; then
-    compset -q
-    words=(ssh-opt "$words[@]" )
-    (( CURRENT++ ))
-    _ssh
-    return
-  elif [[ -n "$state" ]]; then
-    if compset -P '*:'; then
-      _files && ret=0
-    elif compset -P '*@'; then
-      _hosts -S: && ret=0
-    else
-      _files && ret=0
-      _hosts -S: && ret=0
-      _users -S@ && ret=0
+    return ret
+    ;;
+  scp)
+    _arguments -s \
+      '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
+      '-P[specify port on remote host]:port number on remote host:' \
+      '-i[select identity file]:SSH identity file:_files' \
+      '-S[specify path to ssh]:path to ssh:_files -g \*\(\*\)' \
+      '-o[give SSH options]:options:->options' \
+      '-p[preserve modification times]' \
+      '-r[recursively copy directories]' \
+      '-v[verbose mode]' \
+      '-B[batch mode]' \
+      '-C[compress data]' \
+      '*:file:->file' && ret=0
+
+    if [[ "$state" = options ]]; then
+      compset -q
+      words=(ssh-opt "$words[@]" )
+      (( CURRENT++ ))
+      _ssh
+      return
+    elif [[ -n "$state" ]]; then
+      if compset -P '*:'; then
+        _files && ret=0
+      elif compset -P '*@'; then
+        _ssh_hosts -S: && ret=0
+      else
+        _files && ret=0
+        _ssh_hosts -S: && ret=0
+        _ssh_users -S@ && ret=0
+      fi
     fi
+    return ret
+    ;;
+  ssh-add)
+    _arguments -s \
+      '-p[read passphrase from stdin]' \
+      '-l[list all identities]' \
+      '-d[remove identity]' \
+      '-D[delete all identities]' \
+      '*:SSH identity file:_files'
+    return
+    ;;
+  ssh-agent)
+    _arguments -s \
+      '(:)-k[kill agent automatically]' \
+      '(:)-s[force sh-style shell]' \
+      '(:)-c[force csh-style shell]' \
+      '*::command: _normal'
+    return
+    ;;
+  ssh-keygen)
+    _arguments \
+      '(-p -c -u -P)-b[specify number of bits in key]:bits in key:' \
+      '(-p -c)-f[key file]:key file:_files' \
+      '(-c -u)-N[specify new passphrase]:new passphrase:' \
+      '(-b -u -f)-P[specify old passphrase]:old passphrase:' \
+      '(-p -u)-C[specify new comment]:new comment:' \
+      '(-b -f -C -u -c)-p[change passphrase of private key file]' \
+      '(-b -f -N -p -u)-c[change comment in private and public key files]' \
+      '(-b -N -C -p -c)-u[change key cipher to default]'
+    return
+    ;;
+  esac
+}
+
+_ssh_users () {
+  _combination accounts_users_hosts users "$@"
+}
+
+_ssh_hosts () {
+  if [[ "$IPREFIX" == *@ ]]; then
+    _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@"
+  else
+    _combination accounts_users_hosts \
+      ${options[-l]:+"users=${options[-l]:q}"} hosts "$@"
   fi
-  return ret
-  ;;
-ssh-add)
-  _arguments -s \
-    '-p[read passphrase from stdin]' \
-    '-l[list all identities]' \
-    '-d[remove identity]' \
-    '-D[delete all identities]' \
-    '*:SSH identity file:_files'
-  return
-  ;;
-ssh-agent)
-  _arguments -s \
-    '(:)-k[kill agent automatically]' \
-    '(:)-s[force sh-style shell]' \
-    '(:)-c[force csh-style shell]' \
-    '*::command: _normal'
-  return
-  ;;
-ssh-keygen)
-  _arguments \
-    '(-p -c -u -P)-b[specify number of bits in key]:bits in key:' \
-    '(-p -c)-f[key file]:key file:_files' \
-    '(-c -u)-N[specify new passphrase]:new passphrase:' \
-    '(-b -u -f)-P[specify old passphrase]:old passphrase:' \
-    '(-p -u)-C[specify new comment]:new comment:' \
-    '(-b -f -C -u -c)-p[change passphrase of private key file]' \
-    '(-b -f -N -p -u)-c[change comment in private and public key files]' \
-    '(-b -N -C -p -c)-u[change key cipher to default]'
-  return
-  ;;
-esac
+}
+
+_ssh "$@"
Index: Completion/User/_users_on
===================================================================
RCS file: _users_on
diff -N _users_on
--- /dev/null	Tue May  5 21:32:27 1998
+++ _users_on	Sun Sep 26 13:48:42 1999
@@ -0,0 +1,11 @@
+#autoload write
+
+local expl
+
+if which users >/dev/null; then
+  _description expl users logged on
+  compadd "$@" "$expl[@]" - $(users) && return 0
+else
+  # Other methods of finding out users logged on should be added here
+  return 1
+fi


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

end of thread, other threads:[~1999-10-11 11:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-11 11:22 PATCH: improvement to user@host completions Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-09-26 14:17 Adam Spiers
1999-09-26 15:02 ` Peter Stephenson
1999-09-26 16:57   ` Bart Schaefer
1999-09-26 23:28   ` Adam Spiers
1999-09-27  7:54 ` Tanaka Akira

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