110 lines
4.1 KiB
Bash
110 lines
4.1 KiB
Bash
# bash completion for rsync
|
|
|
|
have rsync &&
|
|
_rsync()
|
|
{
|
|
# TODO: _split_longopt
|
|
|
|
local cur prev shell i userhost path
|
|
|
|
COMPREPLY=()
|
|
cur=`_get_cword :`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
_expand || return 0
|
|
|
|
case "$prev" in
|
|
--config|--password-file|--include-from|--exclude-from)
|
|
_filedir
|
|
return 0
|
|
;;
|
|
-T|--temp-dir|--compare-dest)
|
|
_filedir -d
|
|
return 0
|
|
;;
|
|
-e|--rsh)
|
|
COMPREPLY=( $( compgen -W 'rsh ssh' -- "$cur" ) )
|
|
return 0
|
|
;;
|
|
--compress-level)
|
|
COMPREPLY=( $( compgen -W '1 2 3 4 5 6 7 8 9' -- "$cur" ) )
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
case "$cur" in
|
|
-*)
|
|
COMPREPLY=( $( compgen -W '--verbose --quiet --checksum --no-motd \
|
|
--checksum --archive --recursive --relative --no-implied-dirs \
|
|
--backup --backup-dir --suffix= --update --inplace --append \
|
|
--append-verify --dirs --links --copy-links \
|
|
--copy-unsafe-links --safe-links --copy-dirlinks \
|
|
--keep-dirlinks --hard-links --perms --executability --chmod= \
|
|
--acls --xattrs --owner --group --devices --copy-devices \
|
|
--specials --times --omit-dir-times --super --fake-super \
|
|
--sparse --dry-run --whole-file --no-whole-file \
|
|
--one-file-system --block-size= --rsh= --rsync-path= \
|
|
--existing --ignore-existing --remove-source-files --delete \
|
|
--delete-before --delete-during --delete-delay --delete-after \
|
|
--delete-excluded --ignore-errors --force --max-delete= \
|
|
--max-size= --min-size= --partial --partial-dir= \
|
|
--delay-updates --prune-empty-dirs --numeric-ids --timeout= \
|
|
--contimeout= --ignore-times --size-only --modify-window= \
|
|
--temp-dir= --fuzzy --compare-dest= --copy-dest= --link-dest= \
|
|
--compress --compress-level= --skip-compress= --cvs-exclude \
|
|
--filter= --exclude= --exclude-from= --include= \
|
|
--include-from= --files-from= --from0 --protect-args
|
|
--address= --port= --sockopts= --blocking-io --no-blocking-io \
|
|
--stats --8-bit-output --human-readable --progress \
|
|
--itemize-changes --out-format= --log-file= \
|
|
--log-file-format= --password-file= --list-only --bwlimit= \
|
|
--write-batch= --only-write-batch= --read-batch= --protocol= \
|
|
--iconv= --ipv4 --ipv6 --version --help --daemon --config= \
|
|
--no-detach' -- "$cur" ) )
|
|
;;
|
|
*:*)
|
|
# find which remote shell is used
|
|
shell=ssh
|
|
for (( i=1; i < COMP_CWORD; i++ )); do
|
|
if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then
|
|
shell=${COMP_WORDS[i+1]}
|
|
break
|
|
fi
|
|
done
|
|
if [[ "$shell" == ssh ]]; then
|
|
# remove backslash escape from :
|
|
cur=${cur/\\:/:}
|
|
userhost=${cur%%?(\\):*}
|
|
path=${cur#*:}
|
|
# unescape spaces
|
|
path=${path//\\\\\\\\ / }
|
|
if [ -z "$path" ]; then
|
|
# default to home dir of specified user on remote host
|
|
path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
|
|
fi
|
|
# escape spaces; remove executables, aliases, pipes and sockets;
|
|
# add space at end of file names
|
|
COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
|
|
command ls -aF1d "$path*" 2>/dev/null | \
|
|
sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \
|
|
-e 's/[^\/]$/& /g' ) )
|
|
fi
|
|
;;
|
|
*)
|
|
_known_hosts_real -c -a "$cur"
|
|
_filedir
|
|
;;
|
|
esac
|
|
|
|
return 0
|
|
} &&
|
|
complete -F _rsync -o nospace -o filenames rsync
|
|
|
|
# Local variables:
|
|
# mode: shell-script
|
|
# sh-basic-offset: 4
|
|
# sh-indent-comment: t
|
|
# indent-tabs-mode: nil
|
|
# End:
|
|
# ex: ts=4 sw=4 et filetype=sh
|