zsh-users
 help / color / mirror / code / Atom feed
From: Hannu Koivisto <azure@iki.fi>
To: Ian Langworth <ian.langworth@gmail.com>
Cc: zsh-users@sunsite.dk
Subject: Re: Mysterious completion of variables
Date: Fri, 18 Nov 2005 13:32:32 +0200	[thread overview]
Message-ID: <87psoynqcv.fsf@trews52.bothi.fi> (raw)
In-Reply-To: <b6c719b90511171236j5988236elda6ac5a4e9d37dc@mail.gmail.com> (Ian Langworth's message of "Thu, 17 Nov 2005 15:36:33 -0500")

Ian Langworth <ian.langworth@gmail.com> writes:

> I have a few variables for hosts that I shell into frequently:
>
>   aspen='me@aspen.mydomain.com'
>   alias aspen="ssh $aspen"
>
> Thus, I'm usually able to do the following:
>
>   scp $aspen:temp .

Since Peter explained that a more complex form is required, I would
like to suggest another approach that avoids such a variable to
begin with.

Add...

Host aspen
Hostname aspen.mydomain.com
User me

...to your ~/.ssh/config file.  This allows you to write 
'scp aspen:temp .' and 'ssh aspen'.

You might also want to replace _ssh_hosts in _ssh with the function
I provided in a mail sent earlier to this list.  I reproduce it
here in order to save you the trouble of finding it from the
archives:

-----8<------------------------------------------------------------
I modified ssh completion to dig host aliases from the
configuration file.  I don't use wildcards in host patterns or give
multiple patterns, so this doesn't attempt to handle such cases.  I
also have no idea whether this modification is otherwise well
written or not; I'm still a beginner in completion hacking.  All
comments appreciated.

I think that a well written version (one that handles multiple
patterns and patterns with wildcards, among the other issues) of
the same subject would be nice as a standard feature.  One might
also want to utilize hosts from the known_hosts file.

_ssh_hosts () {
  if [[ "$IPREFIX" == *@ ]]; then
    _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
  else
    _combination -s '[:@]' my-accounts users-hosts \
      ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
  fi
  if [[ -r "$HOME/.ssh/config" ]]; then
      local IFS=" 	" key host
      while read key host; do
          if [[ "$key" == (#i)host ]]; then
              _wanted hosts expl host \
                  compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" "$host"
          fi
      done < "$HOME/.ssh/config"
  fi
}
-----8<------------------------------------------------------------

This allows you to say 'scp a<tab>' and get 'scp aspen:' assuming
you don't have other hosts beginning with 'a'.  I hope it works
with _ssh of recent zsh versions, I haven't tested; I made a copy
of _ssh from an older version to a personal function directory with
higher priority and modified that.

-- 
Hannu


  parent reply	other threads:[~2005-11-18 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-17 20:36 Ian Langworth
2005-11-18 10:21 ` Peter Stephenson
2005-11-18 11:32 ` Hannu Koivisto [this message]
2005-11-18 11:47   ` Peter Stephenson
2005-11-18 14:20     ` Ian Langworth
2005-11-18 17:38     ` Wayne Davison

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=87psoynqcv.fsf@trews52.bothi.fi \
    --to=azure@iki.fi \
    --cc=ian.langworth@gmail.com \
    --cc=zsh-users@sunsite.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).