check_version() {
    local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"
    local installed_script="$(borgmatic --bash-completion 2> /dev/null)"
    if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];        then cat << EOF

Your bash completions script is from a different version of borgmatic than is
currently installed. Please upgrade your script so your completions match the
command-line flags in your installed borgmatic! Try this to upgrade:

    sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"
    source $BASH_SOURCE

EOF
    fi
}
complete_borgmatic() {
    if [[ " ${COMP_WORDS[*]} " =~ " rcreate " ]]; then
        COMPREPLY=($(compgen -W "-e --encryption --source-repository --other-repo --repository --copy-crypt-key --append-only --storage-quota --make-parent-dirs -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " init " ]]; then
        COMPREPLY=($(compgen -W "-e --encryption --source-repository --other-repo --repository --copy-crypt-key --append-only --storage-quota --make-parent-dirs -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -I " ]]; then
        COMPREPLY=($(compgen -W "-e --encryption --source-repository --other-repo --repository --copy-crypt-key --append-only --storage-quota --make-parent-dirs -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " transfer " ]]; then
        COMPREPLY=($(compgen -W "--repository --source-repository --archive --upgrader --progress -a --match-archives --glob-archives --sort-by --first --last -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " prune " ]]; then
        COMPREPLY=($(compgen -W "--stats --list -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -p " ]]; then
        COMPREPLY=($(compgen -W "--stats --list -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " compact " ]]; then
        COMPREPLY=($(compgen -W "--progress --cleanup-commits --threshold -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " create " ]]; then
        COMPREPLY=($(compgen -W "--progress --stats --list --files --json -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -C " ]]; then
        COMPREPLY=($(compgen -W "--progress --stats --list --files --json -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " check " ]]; then
        COMPREPLY=($(compgen -W "--progress --repair --only --force -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -k " ]]; then
        COMPREPLY=($(compgen -W "--progress --repair --only --force -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " extract " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --path --restore-path --destination --strip-components --progress -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -x " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --path --restore-path --destination --strip-components --progress -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " export-tar " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --path --destination --tar-filter --list --files --strip-components -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " mount " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --mount-point --path --foreground --options -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -m " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --mount-point --path --foreground --options -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " umount " ]]; then
        COMPREPLY=($(compgen -W "--mount-point -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -u " ]]; then
        COMPREPLY=($(compgen -W "--mount-point -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " restore " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --database -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -r " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --database -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " rlist " ]]; then
        COMPREPLY=($(compgen -W "--repository --short --format --json -P --prefix -a --match-archives --glob-archives --sort-by --first --last -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " list " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --path --find --short --format --json -P --prefix -a --match-archives --glob-archives --successful --sort-by --first --last -e --exclude --exclude-from --pattern --patterns-from -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -l " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --path --find --short --format --json -P --prefix -a --match-archives --glob-archives --successful --sort-by --first --last -e --exclude --exclude-from --pattern --patterns-from -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " rinfo " ]]; then
        COMPREPLY=($(compgen -W "--repository --json -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " info " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --json -P --prefix -a --match-archives --glob-archives --sort-by --first --last -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " -i " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive --json -P --prefix -a --match-archives --glob-archives --sort-by --first --last -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " break-lock " ]]; then
        COMPREPLY=($(compgen -W "--repository -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    if [[ " ${COMP_WORDS[*]} " =~ " borg " ]]; then
        COMPREPLY=($(compgen -W "--repository --archive -- -h --help rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
    fi
    COMPREPLY=($(compgen -W "rcreate init -I transfer prune -p compact create -C check -k extract -x export-tar mount -m umount -u restore -r rlist list -l rinfo info -i break-lock borg -h --help -c --config --excludes -n --dry-run -nc --no-color -v --verbosity --syslog-verbosity --log-file-verbosity --monitoring-verbosity --log-file --override --no-environment-interpolation --bash-completion --version" -- "${COMP_WORDS[COMP_CWORD]}"))
    (check_version &)
}

complete -o bashdefault -o default -F complete_borgmatic borgmatic
