Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'This much more than ssh!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
This much more than ssh!
Authored by: Cadre on Nov 29, '01 03:11:02PM

Wow! Trying to find a pattern that matches for both styles of scp was a pain in the ass (the first style being transfering a file to a server the second being receiving a file from a server). I eventually found one that partially worked and modified it to work better.

I recommend only using the first completion. The second two completions, well, they are for when you want to show off. :-)


# Simple by Aaron Linville <aaron@linville.org>
complete {scp,rcp} 'C@[./]*@f@' 'n/*/`list_all_hostnames`/:'

# From Michael Schroeder <mlschroe@immd4.informatik.uni-erlangen.de>
# This one will rsh to the file to fetch the list of files!
#complete rcp 'c%*@*:%`set q=$:-0;set q="$q:s/@/ /";set q="$q:s/:/ /";set q=($q " ");rsh $q[2] -l $q[1] ls -dp $q[3]*`%' 'c%*:%`set q=$:-0;set q="$q:s/:/ /";set q=($q " ");rsh $q[1] ls -dp $q[2]*`%' 'c%*@%`list_all_hostnames`%:' 'C@[./$~]*@f@' 'n/*/`list_all_hostnames`/:'
#complete scp 'c%*@*:%`set q=$:-0;set q="$q:s/@/ /";set q="$q:s/:/ /";set q=($q " ");ssh $q[2] -l $q[1] ls -dp $q[3]*`%' 'c%*:%`set q=$:-0;set q="$q:s/:/ /";set q=($q " ");ssh $q[1] ls -dp $q[2]*`%' 'c%*@%`list_all_hostnames`%:' 'C@[./$~]*@f@' 'n/*/`list_all_hostnames`/:'


Now a couple notes on typing the correct patterns to match mine. When transfering files, remember to put dot slash at the beginning of the files to be transfered (yes, it does work with a list of files!!!). When sending files, if you would like completion when specifying the destination directory or file, you need to remember the dot slash at the beginning of the path also.

One last thing, you can't specify a username for a host (this breaks the pattern matching). Of course, you really shouldn't be specifying a username on the commandline. Specify the username in your ./.ssh/config file. i.e.:

Host *.nowhere.net
User linvilaw

So following are example commands that could have been generated with completion:
linville:home %scp ./source.c somemachine.nowhere.net:.
linville:home %scp somemachine.nowhere.net:.source.c ./source.c



[ Reply to This | # ]
I fixed the username!
Authored by: serversurfer on Nov 29, '01 05:51:34PM
A little playing around with Cadre's complete yielded:
complete {scp,rcp} 'C@[./]*@f@' 'c/*@/`list_all_hostnames`/:' 'n/*/`list_all_hostnames`/:'

This will still allow you to tab-complete hostnames after specifying a username.
scp root@ot[TAB]

becomes
scp root@otherhost:

I wanted this because sometimes I do work on other boxen as root, but I agree with Cadre's assertion that you should specify your normal username for the other box in ~/.ssh/config.

[ Reply to This | # ]