1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# bash completion for rsync -*- shell-script -*-
_comp_cmd_rsync()
{
local cur prev words cword was_split comp_args
_comp_initialize -s -n : -- "$@" || return
local noargopts='!(-*|*[Te]*)'
# shellcheck disable=SC2254
case $prev in
--config | --password-file | --include-from | --exclude-from | \
--files-from | --log-file | --write-batch | --only-write-batch | \
--read-batch)
compopt +o nospace
_comp_compgen_filedir
return
;;
--temp-dir | --compare-dest | --backup-dir | --partial-dir | \
--copy-dest | --link-dest | -${noargopts}T)
compopt +o nospace
_comp_compgen_filedir -d
return
;;
--rsh | -${noargopts}e)
compopt +o nospace
_comp_compgen -- -W 'rsh ssh'
return
;;
--compress-level)
compopt +o nospace
_comp_compgen -- -W '{1..9}'
return
;;
--info)
_comp_delimited , -W '
backup{,0}
copy{,0}
del{,0}
flist{,0,1,2}
misc{,0,1,2}
mount{,0}
name{,0,1,2}
nonreg{,0,1}
progress{,0,1,2}
remove{,0}
skip{,0,1,2}
stats{,0,1,2,3}
symsafe{,0}
all{,0,1,2,3,4}
none
help
'
return
;;
esac
[[ $was_split ]] && return
_comp_expand || return
case $cur in
-*)
local tmp
# Account for the fact that older rsync versions (before cba00be6,
# meaning before v3.2.0) contain the following unusual line in
# --help:
# "(-h) --help show this help (-h is --help only if used alone)"
_comp_compgen -Rv tmp help - <<<"$("$1" --help 2>&1 | command sed -e 's/^([^)]*)//')"
_comp_compgen -- -W '"${tmp[@]}"
--daemon --old-d{,irs}
--no-{blocking-io,detach,whole-file,inc-recursive,i-r}' -X '--no-OPTION'
[[ ${COMPREPLY-} == *= ]] || compopt +o nospace
;;
*:*)
# find which remote shell is used
local i shell=ssh
for ((i = 1; i < cword; i++)); do
if [[ ${words[i]} == -@(e|-rsh) ]]; then
shell=${words[i + 1]}
break
fi
done
[[ $shell == ssh ]] && _comp_compgen -x scp remote_files
;;
*)
_comp_compgen_known_hosts -c -a -- "$cur"
_comp_compgen -ax scp local_files
;;
esac
} &&
complete -F _comp_cmd_rsync -o nospace rsync
# ex: filetype=sh
|