# (C) 2011-2025 magicant

# Completion script for the "git-config" command.
# Supports Git 2.48.1.

function completion/git-config {
        WORDS=(git config "${WORDS[2,-1]}")
        command -f completion//reexecute
}

function completion/git::config:arg {

        OPTIONS=( #>#
        "--add; add a new line to the option value"
        "--blob:; specify an object to save config"
        "--bool; ensure the option value is a boolean"
        "--bool-or-int; ensure the option value is a boolean or integer"
        "--default:; specify a default to show if the option is not set"
        "e --edit; start an editor to edit the config file"
        "--expiry-date; expand the date value to a timestamp"
        "f: --file:; specify the config file path"
        "--get; show an option value"
        "--get-all; show all values for an option"
        "--get-color; show ANSI color escape sequence"
        "--get-colorbool; check if output should be colored"
        "--get-regexp; show options whose keys match the specified regular expression"
        "--get-urlmatch; show option with a key matching the specified URL"
        "--global; get or set the global options"
        "--includes; apply include.* directives"
        "--int; ensure the option value is an integer"
        "l --list; show all options set"
        "--local; get or set the repository-specific options"
        "--name-only; show only the names of options"
        "--no-includes; do not apply include.* directives"
        "--no-type; do not canonicalize values"
        "z --null; print a null byte after each key-value pair"
        "--path; perform tilde expansion when printing option values"
        "--remove-section; remove a section"
        "--rename-section; rename a section"
        "--replace-all; replace all matching values"
        "--show-origin; show options with their specifying file"
        "--show-scope; show options with their scope"
        "--system; get or set the system-wide options"
        "--type:; canonicalize values under specified constraint"
        "--unset; remove (part of) an option"
        "--unset-all; remove (all matching parts of) an option"
        "--worktree; get or set the worktree-specific options"
        ) #<#

        command -f completion//parseoptions -es
        case $ARGOPT in
                (-)
                        command -f completion//getoperands
                        case "${WORDS[1]}" in ([gs]et|unset)
                                        OPTIONS=("$OPTIONS" #>#
                                        "--all; operate on all values of multi-valued options"
                                        "--value:; specify the option value to operate on"
                                        "--fixed-value; match the option value exactly (with --value)"
                                        ) #<#
                        esac
                        case "${WORDS[1]}" in
                                (get)
                                        OPTIONS=("$OPTIONS" #>#
                                        "--regexp; show options whose keys match the specified regular expression"
                                        "--url:; show option with a section name matching the specified URL"
                                        ) #<#
                                        ;;
                                (set)
                                        OPTIONS=("$OPTIONS" #>#
                                        "--append; add a new value to a multi-valued option"
                                        ) #<#
                                        ;;
                        esac
                        command -f completion//completeoptions
                        ;;
                (f|--file)
                        complete -P "$PREFIX" -f
                        ;;
                (--type)
                        complete -P "$PREFIX" bool int bool-or-int path expiry-date color
                        ;;
                ('')
                        command -f completion//getoperands
                        if [ "${WORDS[#]}" -eq 0 ]; then #>>#
                                complete -P "$PREFIX" -D "modify value with an editor" edit
                                complete -P "$PREFIX" -D "show value for specific key" get
                                complete -P "$PREFIX" -D "show all key-value pairs" list
                                complete -P "$PREFIX" -D "rename group of keys" rename-section
                                complete -P "$PREFIX" -D "remove group of keys" remove-section
                                complete -P "$PREFIX" -D "set value for specific key" set
                                complete -P "$PREFIX" -D "remove value for specific key" unset
                        fi #<<#
                        command -f completion//git::completeoptionname
                        ;;
        esac

}

function completion//git::completeoptionname {

        typeset usesuffix= suffix
        if [ $# -gt 0 ]; then
                usesuffix=true suffix=$1
        fi

        typeset word="${TARGETWORD#"$PREFIX"}"

        # complete existing settings
        typeset word2 prefix2 name value
        word2="${word##*.}"
        prefix2="${TARGETWORD%"$word2"}"
        while read -r name value; do
                name=${name#"$prefix2"}
                case $name in
                        (*.*)
                                name=${name%%.*}
                                complete -P "$prefix2" -S . -T -- "$name"
                                ;;
                        (*)
                                complete -P "$prefix2" ${usesuffix:+-S "$suffix" -T} -- \
                                        "$name"
                                ;;
                esac
        done 2>/dev/null <(git config --get-regexp "${word//./'\.'}.*")

        case $word in
                (add.*)
                        PREFIX=${PREFIX}add. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                ignoreErrors
                        ;; #<<#
                (advice.*)
                        PREFIX=${PREFIX}advice. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                addEmbeddedRepo addEmbeddedRepo addIgnoredFile \
                                amWorkDir ambiguousFetchRefspec \
                                checkoutAmbiguousRemoteBranchName \
                                commitBeforeMerge detachedHead diverging \
                                fetchShowForcedUpdates forceDeleteBranch \
                                ignoredHook implicitIdentity mergeConflict \
                                nestedTag pushAlreadyExists pushFetchFirst \
                                pushNeedsForce pushNonFFCurrent \
                                pushNonFFMatching pushRefNeedsUpdate \
                                pushUnqualifiedRefname pushUpdateRejected \
                                rebaseTodoError refSyntax resetNoRefresh \
                                resolveConflict rmHints sequencerInUse \
                                skippedCherryPicks sparseIndexExpanded \
                                statusAheadBehind statusHints statusUoption \
                                submoduleAlternateErrorStrategyDie \
                                submoduleMergeConflict submodulesNotUpdated \
                                suggestDetachingHead updateSparsePath \
                                waitingForEditor worktreeAddOrphan
                        ;; #<<#
                (alias.*)
                        PREFIX=${PREFIX}alias. #>>#
                        command -f completion/git::completealias ${usesuffix:+"$suffix"}
                        ;;
                (am.*)
                        PREFIX=${PREFIX}am. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                keepcr threeWay
                        ;; #<<#
                (apply.*)
                        PREFIX=${PREFIX}apply. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                ignorewhitespace whitespace
                        ;; #<<#
                (attr.*)
                        PREFIX=${PREFIX}attr. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                tree
                        ;; #<<#
                (author.*|committer.*)
                        word=${word#*.}
                        PREFIX=${TARGETWORD%"$word"} #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                email name
                        ;; #<<#
                (bitmapPseudoMerge.*.*)
                        word=${word#bitmapPseudoMerge.*.}
                        PREFIX=${TARGETWORD%"$word"} #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                pattern decay sampleRate threshold maxMerges \
                                stableThreshold stableSize
                        ;; #<<#
                (blame.*)
                        PREFIX=${PREFIX}blame. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                blankBoundary coloring date showEmail showRoot \
                                ignoreRevsFile markUnblamableLines \
                                markIgnoredLines
                        ;; #<<#
                (branch.*.*)
                        word=${word#branch.*.}
                        PREFIX=${TARGETWORD%"$word"} #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                remote pushRemote merge mergeOptions rebase \
                                description
                        ;; #<<#
                (branch.*)
                        PREFIX=${PREFIX}branch. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                autoSetupMerge autoSetupRebase sort
                        #<<#
                        command -f completion/git::completeref \
                                abbrprefixes=refs/heads/ dontcompletefull=true \
                                suffix=. --branches
                        ;;
                (browser.*.*|difftool.*.*|man.*.*)
                        word=${word#*.*.}
                        PREFIX=${TARGETWORD%"$word"} #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                cmd path
                        ;; #<<#
                # (bundle.*) not yet supported
                (checkout.*)
                        PREFIX=${PREFIX}checkout. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                defaultRemote guess workers \
                                thresholdForParallelism
                        ;; #<<#
                (clean.*)
                        PREFIX=${PREFIX}clean. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                requireForce
                        ;; #<<#
                (clone.*)
                        PREFIX=${PREFIX}clone. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                defaultRemoteName rejectShallow filterSubmodules
                        ;; #<<#
                (color.advice.*)
                        PREFIX=${PREFIX}color.advice. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                hint
                        ;; #<<#
                (color.blame.*)
                        PREFIX=${PREFIX}color.blame. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                highlightRecent repeatedLines
                        ;; #<<#
                (color.branch.*)
                        PREFIX=${PREFIX}color.branch. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                current local plain remote
                        ;; #<<#
                (color.diff.*)
                        PREFIX=${PREFIX}color.diff. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                context contextBold contextDimmed commit frag \
                                func meta new newBold newDimmed newMoved \
                                newMovedDimmed newMovedAlternative \
                                newMovedAlternativeDimmed old oldBold oldDimmed\
                                oldMoved oldMovedDimmed oldMovedAlternative \
                                oldMovedAlternativeDimmed plain whitespace
                        ;; #<<#
                (color.decorate.*)
                        PREFIX=${PREFIX}color.decorate. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                branch HEAD remoteBranch stash tag grafted
                        ;; #<<#
                (color.grep.*)
                        PREFIX=${PREFIX}color.grep. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                context filename function lineNumber column \
                                match matchContext matchSelected selected \
                                separator
                        ;; #<<#
                (color.interactive.*)
                        PREFIX=${PREFIX}color.interactive. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                error header help prompt
                        ;; #<<#
                (color.push.*)
                        PREFIX=${PREFIX}color.push. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                error
                        ;; #<<#
                (color.remote.*)
                        PREFIX=${PREFIX}color.remote. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                error hint success warning
                        ;; #<<#
                (color.status.*)
                        PREFIX=${PREFIX}color.status. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                added branch changed header localBranch \
                                nobranch remoteBranch unmerged untracked updated
                        ;; #<<#
                (color.transport.*)
                        PREFIX=${PREFIX}color.transport. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                rejected
                        ;; #<<#
                (color.*)
                        PREFIX=${PREFIX}color. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                advice branch diff grep interactive pager push \
                                remote showBranch status transport ui
                        complete -P "$PREFIX" -S . -T -- \
                                advice blame branch diff decorate grep \
                                interactive push status transport
                        ;; #<<#
                (column.*)
                        PREFIX=${PREFIX}column. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                ui branch clean status tag
                        ;; #<<#
                (commit.*)
                        PREFIX=${PREFIX}commit. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                cleanup gpgSign status template verbose
                        ;; #<<#
                (commitGraph.*)
                        PREFIX=${PREFIX}commitGraph. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                generationVersion maxNewFilters \
                                readChangedPaths changedPathsVersion
                        ;; #<<#
                (completion.*)
                        PREFIX=${PREFIX}completion. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                commands
                        ;; #<<#
                (core.*)
                        PREFIX=${PREFIX}core. #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                abbrev alternateRefsCommand \
                                alternateRefsPrefixes askPass attributesFile \
                                autocrlf bare bigFileThreshold \
                                checkRoundtripEncoding checkStat commentChar \
                                commentString commitGraph compression \
                                createObject deltaBaseCacheLimit editor eol \
                                excludesFile fileMode filesRefLockTimeout \
                                fsmonitor fsmonitorHookVersion fsync \
                                fsyncMethod fsyncObjectFiles gitProxy \
                                hideDotFiles hooksPath ignoreCase \
                                ignoreCygwinFSTricks ignoreStat ignorecase \
                                logAllRefUpdates looseCompression maxTreeDepth \
                                multiPackIndex notesRef packedGitLimit \
                                packedGitWindowSize packedRefsTimeout pager \
                                precomposeUnicode preferSymlinkRefs \
                                preloadIndex protectHFS quotePath \
                                repositoryFormatVersion \
                                restrictinheritedhandles safecrlf \
                                sharedRepository sparseCheckout \
                                sparseCheckoutCone splitIndex sshCommand \
                                symlinks trustctime unsetenvvars untrackedCache\
                                useReplaceRefs warnAmbiguousRefs whitespace \
                                worktree
                        ;; #<<#
                (credential.*)
                        word=${word#credential.*.}
                        PREFIX=${TARGETWORD%"$word"} #>>#
                        complete -P "$PREFIX" ${usesuffix:+-S "$suffix" -T} -- \
                                helper interactive useHttpPath sanitizePrompt \
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          