//
// This file is automatically generated by generate_auto_job.
// Edits will be automatically overwritten if the build is
// run in maintainer mode.
//
// clang-format off
//
static const std::vector AUTO_COMPLETION_BASH = {
R"~(# qpdf bash completion)~",
R"~(#)~",
R"~(# Most of this logic was generated by Anthropic Claude Opus 4.7. The)~",
R"~(# tabular data is automatically generated.)~",
R"~(#)~",
R"~(# Design note: bash's default COMP_WORDBREAKS contains '=', which makes)~",
R"~(# "--opt=<cursor>" awkward — bash thinks the current word is only the text)~",
R"~(# after the '='. Rather than fight this with brittle quoting hacks, this)~",
R"~(# completion accepts the default bash behavior:)~",
R"~(#   * --opt=<TAB>        completes <value> against the option's value set)~",
R"~(#   * --opt= <TAB>       (with an inserted space) falls through to bash's)~",
R"~(#                        normal positional filename completion, which gets)~",
R"~(#                        you $VAR and ~ expansion for free.)~",
R"~(# The second form is the intended workaround for filename values in bash;)~",
R"~(# zsh handles --opt=<TAB> filename completion natively and is the more)~",
R"~(# functional of the two shells.)~",
R"~()~",
R"~(# Per-option attributes, keyed by "<table>.<option>".)~",
R"~(# _QPDF_ARITY:  bare | opt | req)~",
R"~(# _QPDF_VALUES: "none" | "file" | space-separated choice list)~",
R"~(# _QPDF_NEXT:   "" | next-table | "@value" (value-dispatched))~",
R"~(# _QPDF_VNEXT:  "<table>.<option>.<value>" -> next table)~",
R"~(declare -gA _QPDF_ARITY _QPDF_VALUES _QPDF_NEXT _QPDF_VNEXT)~",
R"~()~",
R"~(_qpdf_def() {)~",
R"~(    _QPDF_ARITY["$1.$2"]=$3)~",
R"~(    _QPDF_VALUES["$1.$2"]=$4)~",
R"~(    _QPDF_NEXT["$1.$2"]=$5)~",
R"~(})~",
R"~()~",
R"~(# BEGIN GENERATED)~",
    R"~(declare -gA _QPDF_OPTS=()~",
    R"~(    [help]="--version --copyright --show-crypto --job-json-help --zopfli --json-help --completion-bash --completion-zsh --help")~",
    R"~(    [global]="--no-default-limits --parser-max-container-size --parser-max-container-size-damaged --parser-max-errors --parser-max-nesting --max-stream-filters")~",
    R"~(    [main]="--add-attachment --allow-weak-crypto --check --check-linearization --coalesce-contents --copy-attachments-from --decrypt --deterministic-id --empty --encrypt --externalize-inline-images --filtered-stream-data --flatten-rotation --generate-appearances --global --ignore-xref-streams --is-encrypted --json-input --keep-inline-images --linearize --list-attachments --newline-before-endstream --no-original-object-ids --no-warn --optimize-images --overlay --pages --password-is-hex-key --preserve-unreferenced --preserve-unreferenced-resources --progress --qdf --raw-stream-data --recompress-flate --remove-acroform --remove-info --remove-metadata --remove-page-labels --remove-structure --replace-input --report-memory-usage --requires-password --remove-restrictions --set-page-labels --show-encryption --show-encryption-key --show-linearization --show-npages --show-pages --show-xref --static-aes-iv --static-id --suppress-password-recovery --suppress-recovery --test-json-schema --underlay --verbose --warning-exit-0 --with-images --compression-level --jpeg-quality --encryption-file-password --force-version --ii-min-bytes --json-object --keep-files-open-threshold --min-version --oi-min-area --oi-min-height --oi-min-width --password --remove-attachment --rotate --show-attachment --show-object --copy-encryption --job-json-file --linearize-pass1 --password-file --update-from-json --json-stream-prefix --collate --split-pages --compress-streams --decode-level --flatten-annotations --json-key --json-stream-data --keep-files-open --normalize-content --object-streams --password-mode --remove-unreferenced-resources --stream-data --json --json-output")~",
    R"~(    [pages]="--range --password --file")~",
    R"~(    [encryption]="--user-password --owner-password --bits")~",
    R"~(    [40-bit-encryption]="--extract --annotate --print --modify")~",
    R"~(    [128-bit-encryption]="--cleartext-metadata --force-V4 --accessibility --extract --print --assemble --annotate --form --modify-other --modify --use-aes")~",
    R"~(    [256-bit-encryption]="--cleartext-metadata --force-R5 --allow-insecure --accessibility --extract --print --assemble --annotate --form --modify-other --modify")~",
    R"~(    [underlay/overlay]="--to --from --repeat --password --file")~",
    R"~(    [attachment]="--replace --key --filename --creationdate --moddate --mimetype --description")~",
    R"~(    [copy-attachment]="--prefix --password")~",
    R"~(    [set-page-labels]="")~",
    R"~())~",
    R"~(_qpdf_def help --version bare "none" "")~",
    R"~(_qpdf_def help --copyright bare "none" "")~",
    R"~(_qpdf_def help --show-crypto bare "none" "")~",
    R"~(_qpdf_def help --job-json-help bare "none" "")~",
    R"~(_qpdf_def help --zopfli bare "none" "")~",
    R"~(_qpdf_def help --json-help opt "1 2 latest" "")~",
    R"~(_qpdf_def global --no-default-limits bare "none" "")~",
    R"~(_qpdf_def global --parser-max-container-size req "none" "")~",
    R"~(_qpdf_def global --parser-max-container-size-damaged req "none" "")~",
    R"~(_qpdf_def global --parser-max-errors req "none" "")~",
    R"~(_qpdf_def global --parser-max-nesting req "none" "")~",
    R"~(_qpdf_def global --max-stream-filters req "none" "")~",
    R"~(_qpdf_def main --add-attachment bare "none" "attachment")~",
    R"~(_qpdf_def main --allow-weak-crypto bare "none" "")~",
    R"~(_qpdf_def main --check bare "none" "")~",
    R"~(_qpdf_def main --check-linearization bare "none" "")~",
    R"~(_qpdf_def main --coalesce-contents bare "none" "")~",
    R"~(_qpdf_def main --copy-attachments-from bare "none" "copy-attachment")~",
    R"~(_qpdf_def main --decrypt bare "none" "")~",
    R"~(_qpdf_def main --deterministic-id bare "none" "")~",
    R"~(_qpdf_def main --empty bare "none" "")~",
    R"~(_qpdf_def main --encrypt bare "none" "encryption")~",
    R"~(_qpdf_def main --externalize-inline-images bare "none" "")~",
    R"~(_qpdf_def main --filtered-stream-data bare "none" "")~",
    R"~(_qpdf_def main --flatten-rotation bare "none" "")~",
    R"~(_qpdf_def main --generate-appearances bare "none" "")~",
    R"~(_qpdf_def main --global bare "none" "")~",
    R"~(_qpdf_def main --ignore-xref-streams bare "none" "")~",
    R"~(_qpdf_def main --is-encrypted bare "none" "")~",
    R"~(_qpdf_def main --json-input bare "none" "")~",
    R"~(_qpdf_def main --keep-inline-images bare "none" "")~",
    R"~(_qpdf_def main --linearize bare "none" "")~",
    R"~(_qpdf_def main --list-attachments bare "none" "")~",
    R"~(_qpdf_def main --newline-before-endstream bare "none" "")~",
    R"~(_qpdf_def main --no-original-object-ids bare "none" "")~",
    R"~(_qpdf_def main --no-warn bare "none" "")~",
    R"~(_qpdf_def main --optimize-images bare "none" "")~",
    R"~(_qpdf_def main --overlay bare "none" "underlay/overlay")~",
    R"~(_qpdf_def main --pages bare "none" "pages")~",
    R"~(_qpdf_def main --password-is-hex-key bare "none" "")~",
    R"~(_qpdf_def main --preserve-unreferenced bare "none" "")~",
    R"~(_qpdf_def main --preserve-unreferenced-resources bare "none" "")~",
    R"~(_qpdf_def main --progress bare "none" "")~",
    R"~(_qpdf_def main --qdf bare "none" "")~",
    R"~(_qpdf_def main --raw-stream-data bare "none" "")~",
    R"~(_qpdf_def main --recompress-flate bare "none" "")~",
    R"~(_qpdf_def main --remove-acroform bare "none" "")~",
    R"~(_qpdf_def main --remove-info bare "none" "")~",
    R"~(_qpdf_def main --remove-metadata bare "none" "")~",
    R"~(_qpdf_def main --remove-page-labels bare "none" "")~",
    R"~(_qpdf_def main --remove-structure bare "none" "")~",
    R"~(_qpdf_def main --replace-input bare "none" "")~",
    R"~(_qpdf_def main --report-memory-usage bare "none" "")~",
    R"~(_qpdf_def main --requires-password bare "none" "")~",
    R"~(_qpdf_def main --remove-restrictions bare "none" "")~",
    R"~(_qpdf_def main --set-page-labels bare "none" "set-page-labels")~",
    R"~(_qpdf_def main --show-encryption bare "none" "")~",
    R"~(_qpdf_def main --show-encryption-key bare "none" "")~",
    R"~(_qpdf_def main --show-linearization bare "none" "")~",
    R"~(_qpdf_def main --show-npages bare "none" "")~",
    R"~(_qpdf_def main --show-pages bare "none" "")~",
    R"~(_qpdf_def main --show-xref bare "none" "")~",
    R"~(_qpdf_def main --static-aes-iv bare "none" "")~",
    R"~(_qpdf_def main --static-id bare "none" "")~",
    R"~(_qpdf_def main --suppress-password-recovery bare "none" "")~",
    R"~(_qpdf_def main --suppress-recovery bare "none" "")~",
    R"~(_qpdf_def main --test-json-schema bare "none" "")~",
    R"~(_qpdf_def main --underlay bare "none" "underlay/overlay")~",
    R"~(_qpdf_def main --verbose bare "none" "")~",
    R"~(_qpdf_def main --warning-exit-0 bare "none" "")~",
    R"~(_qpdf_def main --with-images bare "none" "")~",
    R"~(_qpdf_def main --compression-level req "none" "")~",
    R"~(_qpdf_def main --jpeg-quality req "none" "")~",
    R"~(_qpdf_def main --encryption-file-password req "none" "")~",
    R"~(_qpdf_def main --force-version req "none" "")~",
    R"~(_qpdf_def main --ii-min-bytes req "none" "")~",
    R"~(_qpdf_def main --json-object req "none" "")~",
    R"~(_qpdf_def main --keep-files-open-threshold req "none" "")~",
    R"~(_qpdf_def main --min-version req "none" "")~",
    R"~(_qpdf_def main --oi-min-area req "none" "")~",
    R"~(_qpdf_def main --oi-min-height req "none" "")~",
    R"~(_qpdf_def main --oi-min-width req "none" "")~",
    R"~(_qpdf_def main --password req "none" "")~",
    R"~(_qpdf_def main --remove-attachment req "none" "")~",
    R"~(_qpdf_def main --rotate req "none" "")~",
    R"~(_qpdf_def main --show-attachment req "none" "")~",
    R"~(_qpdf_def main --show-object req "none" "")~",
    R"~(_qpdf_def main --copy-encryption req "file" "")~",
    R"~(_qpdf_def main --job-json-file req "file" "")~",
    R"~(_qpdf_def main --linearize-pass1 req "file" "")~",
    R"~(_qpdf_def main --password-file req "file" "")~",
    R"~(_qpdf_def main --update-from-json req "file" "")~",
    R"~(_qpdf_def main --json-stream-prefix req "file" "")~",
    R"~(_qpdf_def main --collate opt "none" "")~",
    R"~(_qpdf_def main --split-pages opt "none" "")~",
    R"~(_qpdf_def main --compress-streams req "y n" "")~",
    R"~(_qpdf_def main --decode-level req "none generalized specialized all" "")~",
    R"~(_qpdf_def main --flatten-annotations req "all print screen" "")~",
    R"~(_qpdf_def main --json-key req "acroform attachments encrypt objectinfo objects outlines pagelabels pages qpdf" "")~",
    R"~(_qpdf_def main --json-stream-data req "none inline file" "")~",
    R"~(_qpdf_def main --keep-files-open req "y n" "")~",
    R"~(_qpdf_def main --normalize-content req "y n" "")~",
    R"~(_qpdf_def main --object-streams req "disable preserve generate" "")~",
    R"~(_qpdf_def main --password-mode req "bytes hex-bytes unicode auto" "")~",
    R"~(_qpdf_def main --remove-unreferenced-resources req "auto yes no" "")~",
    R"~(_qpdf_def main --stream-data req "compress preserve uncompress" "")~",
    R"~(_qpdf_def main --json opt "1 2 latest" "")~",
    R"~(_qpdf_def main --json-output opt "2 latest" "")~",
    R"~(_qpdf_def pages --range req "none" "")~",
    R"~(_qpdf_def pages --password req "none" "")~",
    R"~(_qpdf_def pages --file req "file" "")~",
    R"~(_qpdf_def encryption --user-password req "none" "")~",
    R"~(_qpdf_def encryption --owner-password req "none" "")~",
    R"~(_qpdf_def encryption --bits req "40 128 256" "@value")~",
    R"~(_qpdf_def 40-bit-encryption --extract req "y n" "")~",
    R"~(_qpdf_def 40-bit-encryption --annotate req "y n" "")~",
    R"~(_qpdf_def 40-bit-encryption --print req "y n" "")~",
    R"~(_qpdf_def 40-bit-encryption --modify req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --cleartext-metadata bare "none" "")~",
    R"~(_qpdf_def 128-bit-encryption --force-V4 bare "none" "")~",
    R"~(_qpdf_def 128-bit-encryption --accessibility req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --extract req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --print req "full low none" "")~",
    R"~(_qpdf_def 128-bit-encryption --assemble req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --annotate req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --form req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --modify-other req "y n" "")~",
    R"~(_qpdf_def 128-bit-encryption --modify req "all annotate form assembly none" "")~",
    R"~(_qpdf_def 128-bit-encryption --use-aes req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --cleartext-metadata bare "none" "")~",
    R"~(_qpdf_def 256-bit-encryption --force-R5 bare "none" "")~",
    R"~(_qpdf_def 256-bit-encryption --allow-insecure bare "none" "")~",
    R"~(_qpdf_def 256-bit-encryption --accessibility req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --extract req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --print req "full low none" "")~",
    R"~(_qpdf_def 256-bit-encryption --assemble req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --annotate req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --form req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --modify-other req "y n" "")~",
    R"~(_qpdf_def 256-bit-encryption --modify req "all annotate form assembly none" "")~",
    R"~(_qpdf_def underlay/overlay --to req "none" "")~",
    R"~(_qpdf_def underlay/overlay --from req "none" "")~",
    R"~(_qpdf_def underlay/overlay --repeat req "none" "")~",
    R"~(_qpdf_def underlay/overlay --password req "none" "")~",
    R"~(_qpdf_def underlay/overlay --file req "file" "")~",
    R"~(_qpdf_def attachment --replace bare "none" "")~",
    R"~(_qpdf_def attachment --key req "none" "")~",
    R"~(_qpdf_def attachment --filename req "none" "")~",
    R"~(_qpdf_def attachment --creationdate req "none" "")~",
    R"~(_qpdf_def attachment --moddate req "none" "")~",
    R"~(_qpdf_def attachment --mimetype req "none" "")~",
    R"~(_qpdf_def attachment --description req "none" "")~",
    R"~(_qpdf_def copy-attachment --prefix req "none" "")~",
    R"~(_qpdf_def copy-attachment --password req "none" "")~",
    R"~(_qpdf_def help --help opt "--accessibility --add-attachment --allow-insecure --allow-weak-crypto --annotate --assemble --bits --check --check-linearization --cleartext-metadata --coalesce-contents --collate --completion-bash --completion-zsh --compress-streams --compression-level --copy-attachments-from --copy-encryption --copyright --creationdate --decode-level --decrypt --description --deterministic-id --empty --encrypt --encryption-file-password --externalize-inline-images --extract --file --filename --filtered-stream-data --flatten-annotations --flatten-rotation --force-R5 --force-V4 --force-version --form --from --generate-appearances --global --help --ignore-xref-streams --ii-min-bytes --is-encrypted --job-json-file --job-json-help --jpeg-quality --json --json-help --json-input --json-key --json-object --json-output --json-stream-data --json-stream-prefix --keep-files-open --keep-files-open-threshold --keep-inline-images --key --linearize --linearize-pass1 --list-attachments --max-stream-filters --mimetype --min-version --moddate --modify --modify-other --newline-before-endstream --no-default-limits --no-original-object-ids --no-warn --normalize-content --object-streams --oi-min-area --oi-min-height --oi-min-width --optimize-images --overlay --owner-password --pages --parser-max-container-size --parser-max-container-size-damaged --parser-max-errors --parser-max-nesting --password --password-file --password-is-hex-key --password-mode --prefix --preserve-unreferenced --preserve-unreferenced-resources --print --progress --qdf --range --raw-stream-data --recompress-flate --remove-acroform --remove-attachment --remove-info --remove-metadata --remove-page-labels --remove-restrictions --remove-structure --remove-unreferenced-resources --repeat --replace --replace-input --report-memory-usage --requires-password --rotate --set-page-labels --show-attachment --show-crypto --show-encryption --show-encryption-key --show-linearization --show-npages --show-object --show-pages --show-xref --split-pages --static-aes-iv --static-id --stream-data --suppress-password-recovery --suppress-recovery --test-json-schema --to --underlay --update-from-json --use-aes --user-password --verbose --version --warning-exit-0 --with-images --zopfli add-attachment advanced-control all attachments completion copy-attachments encryption exit-status general global help inspection json modification overlay-underlay page-ranges page-selection pdf-dates testing transformation usage" "")~",
    R"~(_qpdf_def help --completion-bash bare "none" "")~",
    R"~(_qpdf_def help --completion-zsh bare "none" "")~",
    R"~(_QPDF_VNEXT[encryption.--bits.40]=40-bit-encryption)~",
    R"~(_QPDF_VNEXT[encryption.--bits.128]=128-bit-encryption)~",
    R"~(_QPDF_VNEXT[encryption.--bits.256]=256-bit-encryption)~",
R"~(# END GENERATED)~",
R"~()~",
R"~(unset -f _qpdf_def)~",
R"~()~",
R"~(# Strip one layer of balanced surrounding "..." or '...' quotes.)~",
R"~(_qpdf_unquote() {)~",
R"~(    local s=$1)~",
R"~(    if [[ ${#s} -ge 2 ]]; then)~",
R"~(        if [[ $s == \"*\" ]]; then s=${s:1:${#s}-2}; fi)~",
R"~(        if [[ $s == \'*\' ]]; then s=${s:1:${#s}-2}; fi)~",
R"~(    fi)~",
R"~(    printf '%s' "$s")~",
R"~(})~",
R"~()~",
R"~(# ---- Completion function --------------------------------------------------)~",
R"~(_qpdf() {)~",
R"~(    # Reassemble COMP_WORDS so a triple "--opt" "=" "val" becomes one logical)~",
R"~(    # token "--opt=<unquoted-val>". Needed because '=' is a wordbreak.)~",
R"~(    local -a prior=())~",
R"~(    local -i j=0 limit=$COMP_CWORD)~",
R"~(    local raw w val)~",
R"~(    # If the current token is completing a value (cursor is at "=" after)~",
R"~(    # --opt, or after "=" after --opt), exclude those tokens from the)~",
R"~(    # prior-arg loop — they belong to the arg being completed, not to)~",
R"~(    # already-processed prior args. Without this, --opt gets processed as)~",
R"~(    # prior and merge_help is cleared before the current-token lookup)~",
R"~(    # runs, which breaks fallback to the help.* table.)~",
R"~(    if [[ ${COMP_WORDS[limit]} == "=" ]] && (( limit >= 1 )) \)~",
R"~(         && [[ ${COMP_WORDS[limit-1]} == --* ]]; then)~",
R"~(        limit=$((limit-1)))~",
R"~(    elif (( limit >= 2 )) && [[ ${COMP_WORDS[limit-1]} == "=" ]] \)~",
R"~(         && [[ ${COMP_WORDS[limit-2]} == --* ]]; then)~",
R"~(        limit=$((limit-2)))~",
R"~(    fi)~",
R"~(    while (( j < limit )); do)~",
R"~(        raw=${COMP_WORDS[j]})~",
R"~(        w=$(_qpdf_unquote "$raw"))~",
R"~(        if [[ $w == --* ]] && (( j+1 < limit )) && [[ ${COMP_WORDS[j+1]} == "=" ]]; then)~",
R"~(            if (( j+2 < limit )); then)~",
R"~(                val=$(_qpdf_unquote "${COMP_WORDS[j+2]}"))~",
R"~(                prior+=( "$w=$val" ))~",
R"~(                j=$((j+3)))~",
R"~(            else)~",
R"~(                prior+=( "$w=" ))~",
R"~(                j=$((j+2)))~",
R"~(            fi)~",
R"~(        else)~",
R"~(            prior+=( "$w" ))~",
R"~(            j=$((j+1)))~",
R"~(        fi)~",
R"~(    done)~",
R"~(    prior=( "${prior[@]:1}" )   # drop argv[0])~",
R"~()~",
R"~(    local cur_table=main)~",
R"~(    local merge_help=1)~",
R"~(    local i p opt key next vk)~",
R"~(    for (( i=0; i<${#prior[@]}; i++ )); do)~",
R"~(        p=${prior[i]})~",
R"~(        if [[ $p == "--" ]]; then)~",
R"~(            cur_table=main; merge_help=0; continue)~",
R"~(        fi)~",
R"~(        if [[ $p == --*=* ]]; then)~",
R"~(            opt=${p%%=*}; val=${p#*=})~",
R"~(        elif [[ $p == --* ]]; then)~",
R"~(            opt=$p; val="")~",
R"~(        else)~",
R"~(            merge_help=0; continue)~",
R"~(        fi)~",
R"~(        key="$cur_table.$opt")~",
R"~(        if [[ -z ${_QPDF_ARITY[$key]+x} ]] && (( merge_help )); then)~",
R"~(            key="help.$opt")~",
R"~(        fi)~",
R"~(        merge_help=0)~",
R"~(        [[ -z ${_QPDF_ARITY[$key]+x} ]] && continue)~",
R"~(        next=${_QPDF_NEXT[$key]})~",
R"~(        if [[ $next == "@value" ]]; then)~",
R"~(            vk="$key.$val")~",
R"~(            [[ -n ${_QPDF_VNEXT[$vk]+x} ]] && cur_table=${_QPDF_VNEXT[$vk]})~",
R"~(        elif [[ -n $next ]]; then)~",
R"~(            cur_table=$next)~",
R"~(        fi)~",
R"~(    done)~",
R"~(    (( ${#prior[@]} == 0 )) && merge_help=1)~",
R"~()~",
R"~(    # Classify current position via COMP_WORDS (already split by bash).)~",
R"~(    local raw_cur=${COMP_WORDS[COMP_CWORD]})~",
R"~(    local mode="" cur_opt="")~",
R"~(    if (( COMP_CWORD >= 2 ))          && [[ ${COMP_WORDS[COMP_CWORD-1]} == "=" ]] \)~",
R"~(           && [[ $(_qpdf_unquote "${COMP_WORDS[COMP_CWORD-2]}") == --* ]]; then)~",
R"~(        # Must be checked before the "--*" option branch: values for options)~",
R"~(        # like --help start with "--" themselves (e.g. --help=--prefix).)~",
R"~(        mode=value)~",
R"~(        cur_opt=$(_qpdf_unquote "${COMP_WORDS[COMP_CWORD-2]}"))~",
R"~(    elif [[ $raw_cur == --* && $raw_cur != *=* ]]; then)~",
R"~(        mode=option)~",
R"~(    elif [[ $raw_cur == "=" ]] && (( COMP_CWORD >= 1 )) \)~",
R"~(             && [[ $(_qpdf_unquote "${COMP_WORDS[COMP_CWORD-1]}") == --* ]]; then)~",
R"~(        mode=value)~",
R"~(        cur_opt=$(_qpdf_unquote "${COMP_WORDS[COMP_CWORD-1]}"))~",
R"~(        raw_cur="")~",
R"~(    elif [[ $raw_cur == --*=* ]]; then)~",
R"~(        mode=value)~",
R"~(        cur_opt=${raw_cur%%=*})~",
R"~(        raw_cur=${raw_cur#*=})~",
R"~(    else)~",
R"~(        mode=positional)~",
R"~(    fi)~",
R"~()~",
R"~(    COMPREPLY=())~",
R"~()~",
R"~(    case $mode in)~",
R"~(        option))~",
R"~(            local all=${_QPDF_OPTS[$cur_table]})~",
R"~(            (( merge_help )) && all+=" ${_QPDF_OPTS[help]}")~",
R"~(            local o a k)~",
R"~(            for o in $all; do)~",
R"~(                [[ $o != "$raw_cur"* ]] && continue)~",
R"~(                k="$cur_table.$o")~",
R"~(                [[ -z ${_QPDF_ARITY[$k]+x} ]] && k="help.$o")~",
R"~(                a=${_QPDF_ARITY[$k]})~",
R"~(                case $a in)~",
R"~(                    bare) COMPREPLY+=( "$o " ) ;;)~",
R"~(                    req)  COMPREPLY+=( "$o=" ) ;;)~",
R"~(                    opt)  COMPREPLY+=( "$o " "$o=" ) ;;)~",
R"~(                esac)~",
R"~(            done)~",
R"~(            compopt -o nospace 2>/dev/null)~",
R"~(            ;;)~",
R"~(        value))~",
R"~(            local key="$cur_table.$cur_opt")~",
R"~(            if [[ -z ${_QPDF_ARITY[$key]+x} ]] && (( merge_help )); then)~",
R"~(                key="help.$cur_opt")~",
R"~(            fi)~",
R"~(            [[ -z ${_QPDF_ARITY[$key]+x} ]] && return 0)~",
R"~(            local vs=${_QPDF_VALUES[$key]})~",
R"~(            case $vs in)~",
R"~(                none) return 0 ;;)~",
R"~(                file))~",
R"~(                    # Best-effort: bash's cur after '=' is just the path)~",
R"~(                    # tail. No ~ / $VAR expansion here; see header comment.)~",
R"~(                    COMPREPLY=( $(compgen -f -- "$raw_cur") ))~",
R"~(                    compopt -o filenames 2>/dev/null)~",
R"~(                    ;;)~",
R"~(                *))~",
R"~(                    local c)~",
R"~(                    for c in $vs; do)~",
R"~(                        [[ $c == "$raw_cur"* ]] && COMPREPLY+=( "$c" ))~",
R"~(                    done)~",
R"~(                    ;;)~",
R"~(            esac)~",
R"~(            ;;)~",
R"~(        positional))~",
R"~(            COMPREPLY=( $(compgen -f -- "$raw_cur") ))~",
R"~(            compopt -o filenames 2>/dev/null)~",
R"~(            ;;)~",
R"~(    esac)~",
R"~(    return 0)~",
R"~(})~",
R"~()~",
R"~(complete -F _qpdf qpdf)~",
};
