Skip to content

Commit 8cbbffa

Browse files
committed
duply: New completion
1 parent c401847 commit 8cbbffa

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ bashcomp_DATA = 2to3 \
8585
dsniff \
8686
dumpdb \
8787
dumpe2fs \
88+
duply \
8889
e2freefrag \
8990
e2label \
9091
ebtables \

completions/duply

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# duply completion -*- shell-script -*-
2+
3+
_duply () {
4+
COMPREPLY=()
5+
local IFS=$' \n'
6+
local cur=$2 prev=$3
7+
local -a opts
8+
# fetch duply profiles from their usual location
9+
pushd ~/.duply >/dev/null
10+
profiles=(*)
11+
popd >/dev/null
12+
commands=(
13+
backup
14+
bkp
15+
cleanup
16+
create
17+
fetch
18+
full
19+
changelog
20+
incr
21+
list
22+
post
23+
pre
24+
purge
25+
purgeFull
26+
purgeIncr
27+
restore
28+
status
29+
txt2man
30+
usage
31+
verify
32+
verifyPath
33+
version
34+
)
35+
36+
chained_commands=(
37+
backup
38+
bkp
39+
cleanup
40+
create
41+
fetch
42+
full
43+
incr
44+
list
45+
post
46+
pre
47+
purge
48+
purgeFull
49+
purgeIncr
50+
restore
51+
status
52+
verify
53+
verifyPath
54+
)
55+
56+
opts=(
57+
--preview
58+
--disable-encryption
59+
)
60+
61+
# autocomplete duply profile name
62+
if [[ $COMP_CWORD == 1 ]]
63+
then
64+
COMPREPLY=( $(compgen -W "${profiles[*]} usage version txt2man changelog" -- "$cur") )
65+
# autocomplete command
66+
elif [[ $COMP_CWORD == 2 ]]
67+
then
68+
if [[ "$cur" == *[_+-]* ]]
69+
then
70+
comp_commands=()
71+
sep=${cur//[!_+-]}
72+
sep="${sep: -1}"
73+
may_continue=0
74+
for chained_command in ${chained_commands[@]}
75+
do
76+
if echo "${cur%%[_+-]*}" | grep -qE "^${chained_command}$"
77+
then
78+
may_continue=1
79+
fi
80+
done
81+
if [[ ${may_continue} != 1 ]]
82+
then
83+
return
84+
fi
85+
86+
for command in "${chained_commands[@]}"
87+
do
88+
if echo "${command}" | grep -q "^${cur##*[_+-]}"
89+
then
90+
comp_commands+=("${cur%[_+-]*}${sep}${command}")
91+
fi
92+
done
93+
COMPREPLY=( $(compgen -W "${comp_commands[*]}" -- "${cur}") )
94+
else
95+
COMPREPLY=( $(compgen -W "${commands[*]}" -- "$cur") )
96+
fi
97+
# autocomplete command option
98+
elif [[ "$cur" == -* ]]
99+
then
100+
# --force only makes sense with purge* and cleanup commands
101+
if echo "${COMP_WORDS[2]}" | egrep -qe 'purge' -e 'cleanup'
102+
then
103+
opts+=(--force)
104+
fi
105+
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
106+
fi
107+
108+
return 0
109+
}
110+
111+
complete -F _duply duply

0 commit comments

Comments
 (0)