I'm regularly downloading files from a remote server, always from the same directory. So I wrote a custom function that I put in my bashrc
:
download_from_myserver () {
for file in "$@"
do
rsync myserver:/home/pierre/downloads/"$file" .
done
}
Right now, the autocompletion works by default with files in the current directory. I would like to change the autocompletion so that bash automatically connects to the server via ssh
and autocompletes with files that are in myserver:/home/pierre/downloads/
.
In case I'm not being clear, here's an example: let's say I have my_file.txt
in the remote directory, I want to be able to do this:
download_from_my_server my_fi
TAB
download_from_my_server my_file.txt
How would I do this ?
Notes : I'm already using a password-less connection, rsync and scp autocomplete work well, that's not the issue. I'm using Ubuntu on both machines if that's important.
in "$@"
is redundant in this case -for
by default loops over the parameters.