Editar : fatiado um pouco mais.
Você pode achar isto útil, da Administração Debian: Uma introdução à conclusão do bash .
Script completo: /some/location/my_ssh_autocomplete_script
(significado apenas como um breve lançamento):
#!/bin/bash
_get_rsync_file_list()
{
# For test:
#local -a flist=("foo" "bar")
#printf "%s " "${flist[@]}"
# Or:
ls /tmp
# For live something in direction of:
#ssh user@host 'ls /path/to/dir' <-- but not ls for other then dirty testing.
}
_GetOptSSH()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
COMPREPLY=( $( compgen -W '-h --help' -- "$cur" ) );;
*)
# This could be done nicer I guess:
COMPREPLY=( $( compgen -W "$(_get_rsync_file_list)" -- "$cur" ) );;
esac
return 0
}
Download do script /some/location/my_ssh_download_script
:
#!/bin/bash
server="myserver"
path="/home/pierre/downloads"
download_from_myserver() {
for file; do
rsync "$server:$path/$file"
done
}
case "$1" in
"-h"|"--help")
echo "Download files from '$server', path: '$path'" >&2
exit 0;;
esac
download_from_myserver "$@"
Em .bash_aliases
:
alias download_from_myserver='/some/location/my_ssh_download_script'
Em .bash_completion
:
# Source complete script:
if . "/some/location/my_ssh_autocomplete_script" >/dev/null 2>&1; then
# Add complete function to download alias:
complete -F _GetOptSSH download_from_myserver
fi