Skip to content

duply: New completion #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ bashcomp_DATA = 2to3 \
dsniff \
dumpdb \
dumpe2fs \
duply \
e2freefrag \
e2label \
ebtables \
Expand Down
111 changes: 111 additions & 0 deletions completions/duply
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# duply completion -*- shell-script -*-

_duply () {
COMPREPLY=()
local IFS=$' \n'
local cur=$2 prev=$3
local -a opts
# fetch duply profiles from their usual location
pushd ~/.duply >/dev/null
profiles=(*)
popd >/dev/null
commands=(
backup
bkp
cleanup
create
fetch
full
changelog
incr
list
post
pre
purge
purgeFull
purgeIncr
restore
status
txt2man
usage
verify
verifyPath
version
)

chained_commands=(
backup
bkp
cleanup
create
fetch
full
incr
list
post
pre
purge
purgeFull
purgeIncr
restore
status
verify
verifyPath
)

opts=(
--preview
--disable-encryption
)

# autocomplete duply profile name
if [[ $COMP_CWORD == 1 ]]
then
COMPREPLY=( $(compgen -W "${profiles[*]} usage version txt2man changelog" -- "$cur") )
# autocomplete command
elif [[ $COMP_CWORD == 2 ]]
then
if [[ "$cur" == *[_+-]* ]]
then
comp_commands=()
sep=${cur//[!_+-]}
sep="${sep: -1}"
may_continue=0
for chained_command in ${chained_commands[@]}
do
if echo "${cur%%[_+-]*}" | grep -qE "^${chained_command}$"
then
may_continue=1
fi
done
if [[ ${may_continue} != 1 ]]
then
return
fi

for command in "${chained_commands[@]}"
do
if echo "${command}" | grep -q "^${cur##*[_+-]}"
then
comp_commands+=("${cur%[_+-]*}${sep}${command}")
fi
done
COMPREPLY=( $(compgen -W "${comp_commands[*]}" -- "${cur}") )
else
COMPREPLY=( $(compgen -W "${commands[*]}" -- "$cur") )
fi
# autocomplete command option
elif [[ "$cur" == -* ]]
then
# --force only makes sense with purge* and cleanup commands
if echo "${COMP_WORDS[2]}" | egrep -qe 'purge' -e 'cleanup'
then
opts+=(--force)
fi
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
fi

return 0
}

complete -F _duply duply