From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2025 invoked from network); 18 Nov 2005 11:33:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 18 Nov 2005 11:33:14 -0000 Received: (qmail 15600 invoked from network); 18 Nov 2005 11:33:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 18 Nov 2005 11:33:07 -0000 Received: (qmail 1818 invoked by alias); 18 Nov 2005 11:33:00 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9687 Received: (qmail 1809 invoked from network); 18 Nov 2005 11:32:59 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 18 Nov 2005 11:32:59 -0000 Received: (qmail 14514 invoked from network); 18 Nov 2005 11:32:59 -0000 Received: from her-isrv.ionific.com (195.197.252.67) by a.mx.sunsite.dk with SMTP; 18 Nov 2005 11:32:58 -0000 Received: from her-gw.ionific.com ([195.197.252.66] helo=trews52.bothi.fi) by her-isrv.ionific.com with esmtp (Exim 3.35 #1 (Debian)) id 1Ed4UB-0003M1-00; Fri, 18 Nov 2005 13:32:55 +0200 Received: from azure by trews52.bothi.fi with local (Exim 3.36 #1 (Debian)) id 1Ed4Ty-0006kA-00; Fri, 18 Nov 2005 13:32:42 +0200 To: Ian Langworth Cc: zsh-users@sunsite.dk Subject: Re: Mysterious completion of variables Mail-copies-to: nobody From: Hannu Koivisto Date: Fri, 18 Nov 2005 13:32:32 +0200 In-Reply-To: (Ian Langworth's message of "Thu, 17 Nov 2005 15:36:33 -0500") Message-ID: <87psoynqcv.fsf@trews52.bothi.fi> User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.4 (i386-pc-linux-gnu) References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Hannu Koivisto Ian Langworth 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' 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