zsh-users
 help / color / mirror / code / Atom feed
* Completing from different ssh config file
@ 2006-11-13 17:23 Jean-Rene David
  2006-11-13 19:57 ` Chris Johnson
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Rene David @ 2006-11-13 17:23 UTC (permalink / raw)
  To: zsh-users

I use the following function to log in to certain hosts:

foo() {
   ssh -i ~/.ssh/id_rsa.foo \
       -F ~/.ssh/config.foo \
       "$*"
}

How would I configure the completion system so
that the hostname is completed from
~/.ssh/config.foo when I use this function?

Right now the hostname isn't completed at all
because the context isn't recognized as a call to
ssh.

Thanks,

-- 
JR


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

* Re: Completing from different ssh config file
  2006-11-13 17:23 Completing from different ssh config file Jean-Rene David
@ 2006-11-13 19:57 ` Chris Johnson
  2006-11-14 12:00   ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Johnson @ 2006-11-13 19:57 UTC (permalink / raw)
  To: zsh-users

Jean-Rene David sent me the following 0.4K:

> I use the following function to log in to certain hosts:
> 
> foo() {
>    ssh -i ~/.ssh/id_rsa.foo \
>        -F ~/.ssh/config.foo \
>        "$*"
> }
> 
> How would I configure the completion system so
> that the hostname is completed from
> ~/.ssh/config.foo when I use this function?
> 
> Right now the hostname isn't completed at all
> because the context isn't recognized as a call to
> ssh.

For this last point, try:

   compdef foo=ssh

This causes zsh to employ ssh completion for foo.  This doesn't really
solve your problem, but I thought I'd share.  (Unless the completion for
ssh recognizes the -F option, in which case an alias may be more
appropriate?  I dunno.)

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


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

* Re: Completing from different ssh config file
  2006-11-13 19:57 ` Chris Johnson
@ 2006-11-14 12:00   ` Peter Stephenson
  2006-11-14 15:58     ` Jean-Rene David
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2006-11-14 12:00 UTC (permalink / raw)
  To: zsh-users

Chris Johnson <cjohnson@cs.utk.edu> wrote:
> > I use the following function to log in to certain hosts:
> > 
> > foo() {
> >    ssh -i ~/.ssh/id_rsa.foo \
> >        -F ~/.ssh/config.foo \
> >        "$*"
> > }
> > 
> > How would I configure the completion system so
> > that the hostname is completed from
> > ~/.ssh/config.foo when I use this function?
> > Right now the hostname isn't completed at all
> > because the context isn't recognized as a call to
> > ssh.
> 
> For this last point, try:
> 
>    compdef foo=ssh
> 
> This causes zsh to employ ssh completion for foo.  This doesn't really
> solve your problem, but I thought I'd share.  (Unless the completion for
> ssh recognizes the -F option, in which case an alias may be more
> appropriate?  I dunno.)

_ssh doesn't recognize the -F option at the moment; this fixes that.
Then an alias certainly ought to do the trick.

alias foo='ssh -i ~/.ssh/id_rsa.foo -F ~/.ssh/config.foo'

I could add a style to pick the config file, but even that's not really
quite what's needed here, and isn't of much general use since ssh either
uses a fixed file or what's on the command line.

Index: Completion/Unix/Command/_ssh
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ssh,v
retrieving revision 1.29
diff -u -r1.29 _ssh
--- Completion/Unix/Command/_ssh	3 Oct 2006 16:24:51 -0000	1.29
+++ Completion/Unix/Command/_ssh	14 Nov 2006 11:53:15 -0000
@@ -323,6 +323,8 @@
 
 _ssh_hosts () {
   local -a config_hosts
+  local config
+  integer ind
 
   if [[ "$IPREFIX" == *@ ]]; then
     _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
@@ -330,7 +332,12 @@
     _combination -s '[:@]' my-accounts users-hosts \
       ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
   fi
-  if [[ -r "$HOME/.ssh/config" ]]; then
+  if (( ind = ${words[(I)-F]} )); then
+    config=$words[ind+1]
+  else
+    config="$HOME/.ssh/config"
+  fi
+  if [[ -r $config ]]; then
     local IFS=$'\t ' key hosts host
     while read key hosts; do
       if [[ "$key" == (#i)host ]]; then
@@ -341,7 +348,7 @@
 	    esac
 	 done
       fi
-    done < "$HOME/.ssh/config"
+    done < "$config"
     if (( ${#config_hosts} )); then
       _wanted hosts expl 'remote host name' \
 	compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts



To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

* Re: Completing from different ssh config file
  2006-11-14 12:00   ` Peter Stephenson
@ 2006-11-14 15:58     ` Jean-Rene David
  2006-11-14 17:14       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Rene David @ 2006-11-14 15:58 UTC (permalink / raw)
  To: zsh-users

* Peter Stephenson [2006.11.14 07:15]:
> Index: Completion/Unix/Command/_ssh
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ssh,v
> retrieving revision 1.29
> diff -u -r1.29 _ssh
> --- Completion/Unix/Command/_ssh	3 Oct 2006 16:24:51 -0000	1.29
> +++ Completion/Unix/Command/_ssh	14 Nov 2006 11:53:15 -0000
> @@ -323,6 +323,8 @@
> 
>  _ssh_hosts () {
>    local -a config_hosts
> +  local config
> +  integer ind
> 
>    if [[ "$IPREFIX" == *@ ]]; then
>      _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
> @@ -330,7 +332,12 @@
>      _combination -s '[:@]' my-accounts users-hosts \
>        ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
>    fi
> -  if [[ -r "$HOME/.ssh/config" ]]; then
> +  if (( ind = ${words[(I)-F]} )); then
> +    config=$words[ind+1]
> +  else
> +    config="$HOME/.ssh/config"
> +  fi
> +  if [[ -r $config ]]; then
>      local IFS=$'\t ' key hosts host
>      while read key hosts; do
>        if [[ "$key" == (#i)host ]]; then
> @@ -341,7 +348,7 @@
>  	    esac
>  	 done
>        fi
> -    done < "$HOME/.ssh/config"
> +    done < "$config"
>      if (( ${#config_hosts} )); then
>        _wanted hosts expl 'remote host name' \
>  	compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts

Very nice. However for it to work perfectly, I had
to change the assignment to:

config=${~words[ind+1]}

In order for "~" to get expanded. Perhaps it's
safer instead of relying on globsubst to be set?

Thansk a lot!

-- 
JR


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

* Re: Completing from different ssh config file
  2006-11-14 15:58     ` Jean-Rene David
@ 2006-11-14 17:14       ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2006-11-14 17:14 UTC (permalink / raw)
  To: zsh-users

Jean-Rene David wrote:
> Very nice. However for it to work perfectly, I had
> to change the assignment to:
> 
> config=${~words[ind+1]}

Thanks, I thought of that and then immediately forgot about it... I'll
commit it.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

end of thread, other threads:[~2006-11-14 17:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-13 17:23 Completing from different ssh config file Jean-Rene David
2006-11-13 19:57 ` Chris Johnson
2006-11-14 12:00   ` Peter Stephenson
2006-11-14 15:58     ` Jean-Rene David
2006-11-14 17:14       ` Peter Stephenson

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