문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| windows:git_bash [2024/02/12 02:21] – [Git Bash 사용하기] taekgu | windows:git_bash [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ======= Git Bash 사용하기 ======= | ||
| + | https:// | ||
| + | |||
| + | 윈도우 WSL보다 더 편리한 것같다. | ||
| + | 하지만 Linux에서 bash,zsh를 사용할 때처럼 window의 git bash로 쓰고 싶은데 windows는 동일하게 작동하지 않는다. | ||
| + | |||
| + | 참조 | ||
| + | * [[https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | === ls시 그룹명이 표현 하도록 하기 === | ||
| + | 파일을 편집 C:\Program Files\Git\etc\nsswitch.conf하고 다음 줄을 변경합니다. | ||
| + | <code conf> | ||
| + | group: files # db | ||
| + | -> | ||
| + | group: files db | ||
| + | </ | ||
| + | 이렇게 하면 시스템이 / | ||
| + | |||
| + | 그러면 다음과 같은 출력을 얻게 됩니다 ls -l. | ||
| + | <code bash> | ||
| + | -rw-r--r-- 1 JoelFan Domain Users 8774 Aug 13 2021 README.md | ||
| + | </ | ||
| + | ====== 편리하게 사용하기 위해서 설정하는 것들 ====== | ||
| + | 다운로드 (사용자홈에 받는다.) | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | 적당히 .bash_profile, | ||
| + | |||
| + | <code bash .bash_profile> | ||
| + | # Enable tab completion | ||
| + | source ~/ | ||
| + | |||
| + | # setting Colors! | ||
| + | green=" | ||
| + | blue=" | ||
| + | purple=" | ||
| + | reset=" | ||
| + | |||
| + | # Change command prompt | ||
| + | source ~/ | ||
| + | export GIT_PS1_SHOWDIRTYSTATE=1 | ||
| + | # 위 코드는 repository에 변경이 있는 경우, 상태에 따라 *나 + 기호가 표시되도록 해줍니다. | ||
| + | # unstaged 변경: * | ||
| + | # staged 변경: + | ||
| + | |||
| + | # setopt PROMPT_SUBST | ||
| + | # MacOS ZSH에서는 PROMPT_SUBST설정 | ||
| + | |||
| + | export PS1=" | ||
| + | |||
| + | # generated by Git for Windows | ||
| + | test -f ~/.profile && . ~/.profile | ||
| + | test -f ~/.bashrc && . ~/.bashrc | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== git-completion.bash ==== | ||
| + | |||
| + | <code bash git-completion.bash> | ||
| + | # bash/zsh completion support for core Git. | ||
| + | # | ||
| + | # Copyright (C) 2006,2007 Shawn O. Pearce < | ||
| + | # Conceptually based on gitcompletion (http:// | ||
| + | # Distributed under the GNU General Public License, version 2.0. | ||
| + | # | ||
| + | # The contained completion routines provide support for completing: | ||
| + | # | ||
| + | # *) local and remote branch names | ||
| + | # *) local and remote tag names | ||
| + | # *) .git/ | ||
| + | # *) git ' | ||
| + | # *) git email aliases for git-send-email | ||
| + | # *) tree paths within ' | ||
| + | # *) file paths within current working directory and index | ||
| + | # *) common --long-options | ||
| + | # | ||
| + | # To use these routines: | ||
| + | # | ||
| + | # 1) Copy this file to somewhere (e.g. ~/ | ||
| + | # 2) Add the following line to your .bashrc/ | ||
| + | # source ~/ | ||
| + | # 3) Consider changing your PS1 to also show the current branch, | ||
| + | # see git-prompt.sh for details. | ||
| + | # | ||
| + | # If you use complex aliases of form '!f() { ... }; f', you can use the null | ||
| + | # command ':' | ||
| + | # completion style. | ||
| + | # tell the completion to use commit completion. | ||
| + | # of form "!sh -c ' | ||
| + | # Note that " | ||
| + | # just like the 'git commit' | ||
| + | # | ||
| + | # If you have a command that is not part of git, but you would still | ||
| + | # like completion, you can use __git_complete: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # Or if it's a main command (i.e. git or gitk): | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # Compatible with bash 3.2.57. | ||
| + | # | ||
| + | # You can set the following environment variables to influence the behavior of | ||
| + | # the completion routines: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # When set to " | ||
| + | # and git-switch completion (e.g., completing " | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # When set to " | ||
| + | # which are hidden by default (e.g. " | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # When set to " | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # When set, uses for-each-ref ' | ||
| + | # case insensitively, | ||
| + | # | ||
| + | |||
| + | case " | ||
| + | *:*) : great ;; | ||
| + | *) | ||
| + | esac | ||
| + | |||
| + | # Discovers the path to the git repository taking any ' | ||
| + | # '-C < | ||
| + | # variable. | ||
| + | __git_find_repo_path () | ||
| + | { | ||
| + | if [ -n " | ||
| + | # we already know where it is | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | __git_repo_path=" | ||
| + | ${__git_dir: | ||
| + | rev-parse --absolute-git-dir 2>/ | ||
| + | elif [ -n " | ||
| + | test -d " | ||
| + | __git_repo_path=" | ||
| + | elif [ -n " | ||
| + | test -d " | ||
| + | __git_repo_path=" | ||
| + | elif [ -d .git ]; then | ||
| + | __git_repo_path=.git | ||
| + | else | ||
| + | __git_repo_path=" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # Deprecated: use __git_find_repo_path() and $__git_repo_path instead | ||
| + | # __gitdir accepts 0 or 1 arguments (i.e., location) | ||
| + | # returns location of .git repo | ||
| + | __gitdir () | ||
| + | { | ||
| + | if [ -z " | ||
| + | __git_find_repo_path || return 1 | ||
| + | echo " | ||
| + | elif [ -d " | ||
| + | echo " | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # Runs git with all the options given as argument, respecting any | ||
| + | # ' | ||
| + | __git () | ||
| + | { | ||
| + | git ${__git_C_args: | ||
| + | ${__git_dir: | ||
| + | } | ||
| + | |||
| + | # Helper function to read the first line of a file into a variable. | ||
| + | # __git_eread requires 2 arguments, the file path and the name of the | ||
| + | # variable, in that order. | ||
| + | # | ||
| + | # This is taken from git-prompt.sh. | ||
| + | __git_eread () | ||
| + | { | ||
| + | test -r " | ||
| + | } | ||
| + | |||
| + | # Runs git in $__git_repo_path to determine whether a pseudoref exists. | ||
| + | # 1: The pseudo-ref to search | ||
| + | __git_pseudoref_exists () | ||
| + | { | ||
| + | local ref=$1 | ||
| + | local head | ||
| + | |||
| + | __git_find_repo_path | ||
| + | |||
| + | # If the reftable is in use, we have to shell out to 'git rev-parse' | ||
| + | # to determine whether the ref exists instead of looking directly in | ||
| + | # the filesystem to determine whether the ref exists. Otherwise, use | ||
| + | # Bash builtins since executing Git commands are expensive on some | ||
| + | # platforms. | ||
| + | if __git_eread " | ||
| + | if [ " | ||
| + | __git show-ref --exists " | ||
| + | return $? | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | [ -f " | ||
| + | } | ||
| + | |||
| + | # Removes backslash escaping, single quotes and double quotes from a word, | ||
| + | # stores the result in the variable $dequoted_word. | ||
| + | # 1: The word to dequote. | ||
| + | __git_dequote () | ||
| + | { | ||
| + | local rest=" | ||
| + | |||
| + | dequoted_word="" | ||
| + | |||
| + | while test -n " | ||
| + | len=${# | ||
| + | dequoted_word=" | ||
| + | rest=" | ||
| + | |||
| + | case " | ||
| + | \\) | ||
| + | ch=" | ||
| + | case " | ||
| + | $' | ||
| + | ;; | ||
| + | *) | ||
| + | dequoted_word=" | ||
| + | ;; | ||
| + | esac | ||
| + | rest=" | ||
| + | ;; | ||
| + | \') | ||
| + | rest=" | ||
| + | len=${# | ||
| + | dequoted_word=" | ||
| + | rest=" | ||
| + | ;; | ||
| + | \") | ||
| + | rest=" | ||
| + | while test -n " | ||
| + | len=${# | ||
| + | dequoted_word=" | ||
| + | rest=" | ||
| + | case " | ||
| + | \\) | ||
| + | ch=" | ||
| + | case " | ||
| + | \" | ||
| + | dequoted_word=" | ||
| + | ;; | ||
| + | $' | ||
| + | ;; | ||
| + | *) | ||
| + | dequoted_word=" | ||
| + | ;; | ||
| + | esac | ||
| + | rest=" | ||
| + | ;; | ||
| + | \" | ||
| + | rest=" | ||
| + | break | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | } | ||
| + | |||
| + | # The following function is based on code from: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # © 2009-2010, Bash Completion Maintainers | ||
| + | # < | ||
| + | # | ||
| + | # This program is free software; you can redistribute it and/or modify | ||
| + | # it under the terms of the GNU General Public License as published by | ||
| + | # the Free Software Foundation; either version 2, or (at your option) | ||
| + | # any later version. | ||
| + | # | ||
| + | # This program is distributed in the hope that it will be useful, | ||
| + | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + | # | ||
| + | # GNU General Public License for more details. | ||
| + | # | ||
| + | # You should have received a copy of the GNU General Public License | ||
| + | # along with this program; if not, see < | ||
| + | # | ||
| + | # The latest version of this software can be obtained here: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # This function can be used to access a tokenized list of words | ||
| + | # on the command line: | ||
| + | # | ||
| + | # | ||
| + | # if test " | ||
| + | # then | ||
| + | # ... | ||
| + | # fi | ||
| + | # | ||
| + | # The argument should be a collection of characters from the list of | ||
| + | # word completion separators (COMP_WORDBREAKS) to treat as ordinary | ||
| + | # characters. | ||
| + | # | ||
| + | # This is roughly equivalent to going back in time and setting | ||
| + | # COMP_WORDBREAKS to exclude those characters. | ||
| + | # make option types like --date=< | ||
| + | # recognize by treating each shell word as a single token. | ||
| + | # | ||
| + | # It is best not to set COMP_WORDBREAKS directly because the value is | ||
| + | # shared with other completion scripts. | ||
| + | # function gets called, COMP_WORDS has already been populated so local | ||
| + | # changes to COMP_WORDBREAKS have no effect. | ||
| + | # | ||
| + | # Output: words_, cword_, cur_. | ||
| + | |||
| + | __git_reassemble_comp_words_by_ref() | ||
| + | { | ||
| + | local exclude i j first | ||
| + | # Which word separators to exclude? | ||
| + | exclude=" | ||
| + | cword_=$COMP_CWORD | ||
| + | if [ -z " | ||
| + | words_=(" | ||
| + | return | ||
| + | fi | ||
| + | # List of word completion separators has shrunk; | ||
| + | # re-assemble words to complete. | ||
| + | for ((i=0, j=0; i < ${# | ||
| + | # Append each nonempty word consisting of just | ||
| + | # word separator characters to the current word. | ||
| + | first=t | ||
| + | while | ||
| + | [ $i -gt 0 ] && | ||
| + | [ -n " | ||
| + | # word consists of excluded word separators | ||
| + | [ " | ||
| + | do | ||
| + | # Attach to the previous token, | ||
| + | # unless the previous token is the command name. | ||
| + | if [ $j -ge 2 ] && [ -n " | ||
| + | ((j--)) | ||
| + | fi | ||
| + | first= | ||
| + | words_[$j]=${words_[j]}${COMP_WORDS[i]} | ||
| + | if [ $i = $COMP_CWORD ]; then | ||
| + | cword_=$j | ||
| + | fi | ||
| + | if (($i < ${# | ||
| + | ((i++)) | ||
| + | else | ||
| + | # Done. | ||
| + | return | ||
| + | fi | ||
| + | done | ||
| + | words_[$j]=${words_[j]}${COMP_WORDS[i]} | ||
| + | if [ $i = $COMP_CWORD ]; then | ||
| + | cword_=$j | ||
| + | fi | ||
| + | done | ||
| + | } | ||
| + | |||
| + | if ! type _get_comp_words_by_ref >/ | ||
| + | _get_comp_words_by_ref () | ||
| + | { | ||
| + | local exclude cur_ words_ cword_ | ||
| + | if [ " | ||
| + | exclude=$2 | ||
| + | shift 2 | ||
| + | fi | ||
| + | __git_reassemble_comp_words_by_ref " | ||
| + | cur_=${words_[cword_]} | ||
| + | while [ $# -gt 0 ]; do | ||
| + | case " | ||
| + | cur) | ||
| + | cur=$cur_ | ||
| + | ;; | ||
| + | prev) | ||
| + | prev=${words_[$cword_-1]} | ||
| + | ;; | ||
| + | words) | ||
| + | words=(" | ||
| + | ;; | ||
| + | cword) | ||
| + | cword=$cword_ | ||
| + | ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | } | ||
| + | fi | ||
| + | |||
| + | # Fills the COMPREPLY array with prefiltered words without any additional | ||
| + | # processing. | ||
| + | # Callers must take care of providing only words that match the current word | ||
| + | # to be completed and adding any prefix and/or suffix (trailing space!), if | ||
| + | # necessary. | ||
| + | # 1: List of newline-separated matching completion words, complete with | ||
| + | # prefix and suffix. | ||
| + | __gitcomp_direct () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | |||
| + | COMPREPLY=($1) | ||
| + | } | ||
| + | |||
| + | # Similar to __gitcomp_direct, | ||
| + | # Callers must take care of providing only words that match the current word | ||
| + | # to be completed and adding any prefix and/or suffix (trailing space!), if | ||
| + | # necessary. | ||
| + | # 1: List of newline-separated matching completion words, complete with | ||
| + | # prefix and suffix. | ||
| + | __gitcomp_direct_append () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | |||
| + | COMPREPLY+=($1) | ||
| + | } | ||
| + | |||
| + | __gitcompappend () | ||
| + | { | ||
| + | local x i=${# | ||
| + | for x in $1; do | ||
| + | if [[ " | ||
| + | COMPREPLY[i++]=" | ||
| + | fi | ||
| + | done | ||
| + | } | ||
| + | |||
| + | __gitcompadd () | ||
| + | { | ||
| + | COMPREPLY=() | ||
| + | __gitcompappend " | ||
| + | } | ||
| + | |||
| + | # Generates completion reply, appending a space to possible completion words, | ||
| + | # if necessary. | ||
| + | # It accepts 1 to 4 arguments: | ||
| + | # 1: List of possible completion words. | ||
| + | # 2: A prefix to be added to each possible completion word (optional). | ||
| + | # 3: Generate possible completion matches for this word (optional). | ||
| + | # 4: A suffix to be appended to each possible completion word (optional). | ||
| + | __gitcomp () | ||
| + | { | ||
| + | local cur_=" | ||
| + | |||
| + | case " | ||
| + | *=) | ||
| + | ;; | ||
| + | --no-*) | ||
| + | local c i=0 IFS=$' \t\n' | ||
| + | for c in $1; do | ||
| + | if [[ $c == " | ||
| + | continue | ||
| + | fi | ||
| + | c=" | ||
| + | if [[ $c == " | ||
| + | case $c in | ||
| + | --*=|*.) ;; | ||
| + | *) c="$c " ;; | ||
| + | esac | ||
| + | COMPREPLY[i++]=" | ||
| + | fi | ||
| + | done | ||
| + | ;; | ||
| + | *) | ||
| + | local c i=0 IFS=$' \t\n' | ||
| + | for c in $1; do | ||
| + | if [[ $c == " | ||
| + | c=" | ||
| + | if [[ $c == " | ||
| + | COMPREPLY[i++]=" | ||
| + | fi | ||
| + | break | ||
| + | fi | ||
| + | c=" | ||
| + | if [[ $c == " | ||
| + | case $c in | ||
| + | *=|*.) ;; | ||
| + | *) c="$c " ;; | ||
| + | esac | ||
| + | COMPREPLY[i++]=" | ||
| + | fi | ||
| + | done | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | # Clear the variables caching builtins' | ||
| + | # the completion script. | ||
| + | if [[ -n ${ZSH_VERSION-} ]]; then | ||
| + | unset ${(M)${(k)parameters[@]}:# | ||
| + | else | ||
| + | unset $(compgen -v __gitcomp_builtin_) | ||
| + | fi | ||
| + | |||
| + | # This function is equivalent to | ||
| + | # | ||
| + | # __gitcomp "$(git xxx --git-completion-helper) ..." | ||
| + | # | ||
| + | # except that the output is cached. Accept 1-3 arguments: | ||
| + | # 1: the git command to execute, this is also the cache key | ||
| + | # 2: extra options to be added on top (e.g. negative forms) | ||
| + | # 3: options to be excluded | ||
| + | __gitcomp_builtin () | ||
| + | { | ||
| + | # spaces must be replaced with underscore for multi-word | ||
| + | # commands, e.g. "git remote add" becomes remote_add. | ||
| + | local cmd=" | ||
| + | local incl=" | ||
| + | local excl=" | ||
| + | |||
| + | local var=__gitcomp_builtin_" | ||
| + | local options | ||
| + | eval " | ||
| + | |||
| + | if [ -z " | ||
| + | local completion_helper | ||
| + | if [ " | ||
| + | completion_helper=" | ||
| + | else | ||
| + | completion_helper=" | ||
| + | fi | ||
| + | # leading and trailing spaces are significant to make | ||
| + | # option removal work correctly. | ||
| + | options=" | ||
| + | |||
| + | for i in $excl; do | ||
| + | options=" | ||
| + | done | ||
| + | eval " | ||
| + | fi | ||
| + | |||
| + | __gitcomp " | ||
| + | } | ||
| + | |||
| + | # Variation of __gitcomp_nl () that appends to the existing list of | ||
| + | # completion candidates, COMPREPLY. | ||
| + | __gitcomp_nl_append () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | __gitcompappend " | ||
| + | } | ||
| + | |||
| + | # Generates completion reply from newline-separated possible completion words | ||
| + | # by appending a space to all of them. | ||
| + | # It accepts 1 to 4 arguments: | ||
| + | # 1: List of possible completion words, separated by a single newline. | ||
| + | # 2: A prefix to be added to each possible completion word (optional). | ||
| + | # 3: Generate possible completion matches for this word (optional). | ||
| + | # 4: A suffix to be appended to each possible completion word instead of | ||
| + | # the default space (optional). | ||
| + | # appended. | ||
| + | __gitcomp_nl () | ||
| + | { | ||
| + | COMPREPLY=() | ||
| + | __gitcomp_nl_append " | ||
| + | } | ||
| + | |||
| + | # Fills the COMPREPLY array with prefiltered paths without any additional | ||
| + | # processing. | ||
| + | # Callers must take care of providing only paths that match the current path | ||
| + | # to be completed and adding any prefix path components, if necessary. | ||
| + | # 1: List of newline-separated matching paths, complete with all prefix | ||
| + | # path components. | ||
| + | __gitcomp_file_direct () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | |||
| + | COMPREPLY=($1) | ||
| + | |||
| + | # use a hack to enable file mode in bash < 4 | ||
| + | compopt -o filenames +o nospace 2>/ | ||
| + | compgen -f / | ||
| + | true | ||
| + | } | ||
| + | |||
| + | # Generates completion reply with compgen from newline-separated possible | ||
| + | # completion filenames. | ||
| + | # It accepts 1 to 3 arguments: | ||
| + | # 1: List of possible completion filenames, separated by a single newline. | ||
| + | # 2: A directory prefix to be added to each possible completion filename | ||
| + | # (optional). | ||
| + | # 3: Generate possible completion matches for this word (optional). | ||
| + | __gitcomp_file () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | |||
| + | # XXX does not work when the directory prefix contains a tilde, | ||
| + | # since tilde expansion is not applied. | ||
| + | # This means that COMPREPLY will be empty and Bash default | ||
| + | # completion will be used. | ||
| + | __gitcompadd " | ||
| + | |||
| + | # use a hack to enable file mode in bash < 4 | ||
| + | compopt -o filenames +o nospace 2>/ | ||
| + | compgen -f / | ||
| + | true | ||
| + | } | ||
| + | |||
| + | # Execute 'git ls-files', | ||
| + | # which case it runs 'git diff-index' | ||
| + | # committed. | ||
| + | # argument, and using the options specified in the second argument. | ||
| + | __git_ls_files_helper () | ||
| + | { | ||
| + | if [ " | ||
| + | __git -C " | ||
| + | --name-only --relative HEAD -- " | ||
| + | else | ||
| + | # NOTE: $2 is not quoted in order to support multiple options | ||
| + | __git -C " | ||
| + | --exclude-standard $2 -- " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | |||
| + | # __git_index_files accepts 1 or 2 arguments: | ||
| + | # 1: Options to pass to ls-files (required). | ||
| + | # 2: A directory path (optional). | ||
| + | # If provided, only files within the specified directory are listed. | ||
| + | # Sub directories are never recursed. | ||
| + | # slash. | ||
| + | # 3: List only paths matching this path component (optional). | ||
| + | __git_index_files () | ||
| + | { | ||
| + | local root=" | ||
| + | |||
| + | __git_ls_files_helper " | ||
| + | awk -F / -v pfx=" | ||
| + | paths[$1] = 1 | ||
| + | } | ||
| + | END { | ||
| + | for (p in paths) { | ||
| + | if (substr(p, 1, 1) != " | ||
| + | # No special characters, easy! | ||
| + | print pfx p | ||
| + | continue | ||
| + | } | ||
| + | |||
| + | # The path is quoted. | ||
| + | p = dequote(p) | ||
| + | if (p == "" | ||
| + | continue | ||
| + | |||
| + | # Even when a directory name itself does not contain | ||
| + | # any special characters, it will still be quoted if | ||
| + | # any of its (stripped) trailing path components do. | ||
| + | # Because of this we may have seen the same directory | ||
| + | # both quoted and unquoted. | ||
| + | if (p in paths) | ||
| + | # We have seen the same directory unquoted, | ||
| + | # skip it. | ||
| + | continue | ||
| + | else | ||
| + | print pfx p | ||
| + | } | ||
| + | } | ||
| + | function dequote(p, | ||
| + | # Skip opening double quote. | ||
| + | p = substr(p, 2) | ||
| + | |||
| + | # Interpret backslash escape sequences. | ||
| + | while ((bs_idx = index(p, " | ||
| + | out = out substr(p, 1, bs_idx - 1) | ||
| + | esc = substr(p, bs_idx + 1, 1) | ||
| + | p = substr(p, bs_idx + 2) | ||
| + | |||
| + | if ((esc_idx = index(" | ||
| + | # C-style one-character escape sequence. | ||
| + | out = out substr(" | ||
| + | esc_idx, 1) | ||
| + | } else if (esc == " | ||
| + | # Uh-oh, a newline character. | ||
| + | # We cannot reliably put a pathname | ||
| + | # containing a newline into COMPREPLY, | ||
| + | # and the newline would create a mess. | ||
| + | # Skip this path. | ||
| + | return "" | ||
| + | } else { | ||
| + | # Must be a \nnn octal value, then. | ||
| + | dec = esc * 64 + \ | ||
| + | substr(p, 1, 1) * 8 + \ | ||
| + | substr(p, 2, 1) | ||
| + | out = out sprintf(" | ||
| + | p = substr(p, 3) | ||
| + | } | ||
| + | } | ||
| + | # Drop closing double quote, if there is one. | ||
| + | # (There is not any if this is a directory, as it was | ||
| + | # already stripped with the trailing path components.) | ||
| + | if (substr(p, length(p), 1) == " | ||
| + | out = out substr(p, 1, length(p) - 1) | ||
| + | else | ||
| + | out = out p | ||
| + | |||
| + | return out | ||
| + | }' | ||
| + | } | ||
| + | |||
| + | # __git_complete_index_file requires 1 argument: | ||
| + | # 1: the options to pass to ls-file | ||
| + | # | ||
| + | # The exception is --committable, | ||
| + | __git_complete_index_file () | ||
| + | { | ||
| + | local dequoted_word pfx="" | ||
| + | |||
| + | __git_dequote " | ||
| + | |||
| + | case " | ||
| + | ?*/*) | ||
| + | pfx=" | ||
| + | cur_=" | ||
| + | ;; | ||
| + | *) | ||
| + | cur_=" | ||
| + | esac | ||
| + | |||
| + | __gitcomp_file_direct " | ||
| + | } | ||
| + | |||
| + | # Lists branches from the local repository. | ||
| + | # 1: A prefix to be added to each listed branch (optional). | ||
| + | # 2: List only branches matching this word (optional; list all branches if | ||
| + | # unset or empty). | ||
| + | # 3: A suffix to be appended to each listed branch (optional). | ||
| + | __git_heads () | ||
| + | { | ||
| + | local pfx=" | ||
| + | |||
| + | __git for-each-ref --format=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Lists branches from remote repositories. | ||
| + | # 1: A prefix to be added to each listed branch (optional). | ||
| + | # 2: List only branches matching this word (optional; list all branches if | ||
| + | # unset or empty). | ||
| + | # 3: A suffix to be appended to each listed branch (optional). | ||
| + | __git_remote_heads () | ||
| + | { | ||
| + | local pfx=" | ||
| + | |||
| + | __git for-each-ref --format=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Lists tags from the local repository. | ||
| + | # Accepts the same positional parameters as __git_heads() above. | ||
| + | __git_tags () | ||
| + | { | ||
| + | local pfx=" | ||
| + | |||
| + | __git for-each-ref --format=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # List unique branches from refs/ | ||
| + | # switch' | ||
| + | # 1: A prefix to be added to each listed branch (optional) | ||
| + | # 2: List only branches matching this word (optional; list all branches if | ||
| + | # unset or empty). | ||
| + | # 3: A suffix to be appended to each listed branch (optional). | ||
| + | __git_dwim_remote_heads () | ||
| + | { | ||
| + | local pfx=" | ||
| + | local fer_pfx=" | ||
| + | |||
| + | # employ the heuristic used by git checkout and git switch | ||
| + | # Try to find a remote branch that cur_es the completion word | ||
| + | # but only output if the branch name is unique | ||
| + | __git for-each-ref --format=" | ||
| + | --sort=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | uniq -u | ||
| + | } | ||
| + | |||
| + | # Lists refs from the local (by default) or from a remote repository. | ||
| + | # It accepts 0, 1 or 2 arguments: | ||
| + | # 1: The remote to list refs from (optional; ignored, if set but empty). | ||
| + | # Can be the name of a configured remote, a path, or a URL. | ||
| + | # 2: In addition to local refs, list unique branches from refs/ | ||
| + | # 'git checkout' | ||
| + | # 3: A prefix to be added to each listed ref (optional). | ||
| + | # 4: List only refs matching this word (optional; list all refs if unset or | ||
| + | # empty). | ||
| + | # 5: A suffix to be appended to each listed ref (optional; ignored, if set | ||
| + | # but empty). | ||
| + | # | ||
| + | # Use __git_complete_refs() instead. | ||
| + | __git_refs () | ||
| + | { | ||
| + | local i hash dir track=" | ||
| + | local list_refs_from=path remote=" | ||
| + | local format refs | ||
| + | local pfx=" | ||
| + | local match=" | ||
| + | local umatch=" | ||
| + | local fer_pfx=" | ||
| + | |||
| + | __git_find_repo_path | ||
| + | dir=" | ||
| + | |||
| + | if [ -z " | ||
| + | if [ -z " | ||
| + | return | ||
| + | fi | ||
| + | else | ||
| + | if __git_is_configured_remote " | ||
| + | # configured remote takes precedence over a | ||
| + | # local directory with the same name | ||
| + | list_refs_from=remote | ||
| + | elif [ -d " | ||
| + | dir=" | ||
| + | elif [ -d " | ||
| + | dir=" | ||
| + | else | ||
| + | list_refs_from=url | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | if test " | ||
| + | then | ||
| + | # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility | ||
| + | umatch=$(echo " | ||
| + | fi | ||
| + | |||
| + | if [ " | ||
| + | if [[ " | ||
| + | pfx=" | ||
| + | fer_pfx=" | ||
| + | cur_=${cur_# | ||
| + | match=${match# | ||
| + | umatch=${umatch# | ||
| + | fi | ||
| + | case " | ||
| + | refs|refs/ | ||
| + | format=" | ||
| + | refs=(" | ||
| + | track="" | ||
| + | ;; | ||
| + | *) | ||
| + | for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do | ||
| + | case " | ||
| + | $match*|$umatch*) | ||
| + | if [ -e " | ||
| + | echo " | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | format=" | ||
| + | refs=(" | ||
| + | " | ||
| + | " | ||
| + | ;; | ||
| + | esac | ||
| + | __git_dir=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | if [ -n " | ||
| + | __git_dwim_remote_heads " | ||
| + | fi | ||
| + | return | ||
| + | fi | ||
| + | case " | ||
| + | refs|refs/ | ||
| + | __git ls-remote " | ||
| + | while read -r hash i; do | ||
| + | case " | ||
| + | *^{}) ;; | ||
| + | *) echo " | ||
| + | esac | ||
| + | done | ||
| + | ;; | ||
| + | *) | ||
| + | if [ " | ||
| + | case " | ||
| + | $match*|$umatch*) echo " | ||
| + | esac | ||
| + | __git for-each-ref --format=" | ||
| + | ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ | ||
| + | " | ||
| + | " | ||
| + | else | ||
| + | local query_symref | ||
| + | case " | ||
| + | $match*|$umatch*) query_symref=" | ||
| + | esac | ||
| + | __git ls-remote " | ||
| + | " | ||
| + | " | ||
| + | while read -r hash i; do | ||
| + | case " | ||
| + | *^{}) ;; | ||
| + | refs/ | ||
| + | *) echo " | ||
| + | esac | ||
| + | done | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | # Completes refs, short and long, local and remote, symbolic and pseudo. | ||
| + | # | ||
| + | # Usage: __git_complete_refs [< | ||
| + | # --remote=< | ||
| + | # configured remote, a path, or a URL. | ||
| + | # --dwim: List unique remote branches for 'git switch' | ||
| + | # --pfx=< | ||
| + | # --cur=< | ||
| + | # word to be completed. | ||
| + | # --sfx=< | ||
| + | # | ||
| + | # --mode=< | ||
| + | # complete all refs, ' | ||
| + | # ' | ||
| + | # --remote is only compatible with --mode=refs. | ||
| + | __git_complete_refs () | ||
| + | { | ||
| + | local remote= dwim= pfx= cur_=" | ||
| + | |||
| + | while test $# != 0; do | ||
| + | case " | ||
| + | --remote=*) remote=" | ||
| + | --dwim) dwim=" | ||
| + | # --track is an old spelling of --dwim | ||
| + | --track) dwim=" | ||
| + | --pfx=*) pfx=" | ||
| + | --cur=*) cur_=" | ||
| + | --sfx=*) sfx=" | ||
| + | --mode=*) mode=" | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | |||
| + | # complete references based on the specified mode | ||
| + | case " | ||
| + | refs) | ||
| + | __gitcomp_direct " | ||
| + | heads) | ||
| + | __gitcomp_direct " | ||
| + | remote-heads) | ||
| + | __gitcomp_direct " | ||
| + | *) | ||
| + | return 1 ;; | ||
| + | esac | ||
| + | |||
| + | # Append DWIM remote branch names if requested | ||
| + | if [ " | ||
| + | __gitcomp_direct_append " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # __git_refs2 requires 1 argument (to pass to __git_refs) | ||
| + | # Deprecated: use __git_complete_fetch_refspecs() instead. | ||
| + | __git_refs2 () | ||
| + | { | ||
| + | local i | ||
| + | for i in $(__git_refs " | ||
| + | echo " | ||
| + | done | ||
| + | } | ||
| + | |||
| + | # Completes refspecs for fetching from a remote repository. | ||
| + | # 1: The remote repository. | ||
| + | # 2: A prefix to be added to each listed refspec (optional). | ||
| + | # 3: The ref to be completed as a refspec instead of the current word to be | ||
| + | # completed (optional) | ||
| + | # 4: A suffix to be appended to each listed refspec instead of the default | ||
| + | # space (optional). | ||
| + | __git_complete_fetch_refspecs () | ||
| + | { | ||
| + | local i remote=" | ||
| + | |||
| + | __gitcomp_direct "$( | ||
| + | for i in $(__git_refs " | ||
| + | echo " | ||
| + | done | ||
| + | )" | ||
| + | } | ||
| + | |||
| + | # __git_refs_remotes requires 1 argument (to pass to ls-remote) | ||
| + | __git_refs_remotes () | ||
| + | { | ||
| + | local i hash | ||
| + | __git ls-remote " | ||
| + | while read -r hash i; do | ||
| + | echo " | ||
| + | done | ||
| + | } | ||
| + | |||
| + | __git_remotes () | ||
| + | { | ||
| + | __git_find_repo_path | ||
| + | test -d " | ||
| + | __git remote | ||
| + | } | ||
| + | |||
| + | # Returns true if $1 matches the name of a configured remote, false otherwise. | ||
| + | __git_is_configured_remote () | ||
| + | { | ||
| + | local remote | ||
| + | for remote in $(__git_remotes); | ||
| + | if [ " | ||
| + | return 0 | ||
| + | fi | ||
| + | done | ||
| + | return 1 | ||
| + | } | ||
| + | |||
| + | __git_list_merge_strategies () | ||
| + | { | ||
| + | LANG=C LC_ALL=C git merge -s help 2>&1 | | ||
| + | sed -n -e '/ | ||
| + | s/\.$// | ||
| + | s/.*:// | ||
| + | s/^[ ]*// | ||
| + | s/[ ]*$// | ||
| + | p | ||
| + | }' | ||
| + | } | ||
| + | |||
| + | __git_merge_strategies= | ||
| + | # 'git merge -s help' (and thus detection of the merge strategy | ||
| + | # list) fails, unfortunately, | ||
| + | # tree. __git_merge_strategies is set to the empty string in | ||
| + | # that case, and the detection will be repeated the next time it | ||
| + | # is needed. | ||
| + | __git_compute_merge_strategies () | ||
| + | { | ||
| + | test -n " | ||
| + | __git_merge_strategies=$(__git_list_merge_strategies) | ||
| + | } | ||
| + | |||
| + | __git_merge_strategy_options=" | ||
| + | histogram diff-algorithm= ignore-space-change ignore-all-space | ||
| + | ignore-space-at-eol renormalize no-renormalize no-renames | ||
| + | find-renames find-renames= rename-threshold=" | ||
| + | |||
| + | __git_complete_revlist_file () | ||
| + | { | ||
| + | local dequoted_word pfx ls ref cur_=" | ||
| + | case " | ||
| + | *..?*:*) | ||
| + | return | ||
| + | ;; | ||
| + | ?*:*) | ||
| + | ref=" | ||
| + | cur_=" | ||
| + | |||
| + | __git_dequote " | ||
| + | |||
| + | case " | ||
| + | ?*/*) | ||
| + | pfx=" | ||
| + | cur_=" | ||
| + | ls=" | ||
| + | pfx=" | ||
| + | ;; | ||
| + | *) | ||
| + | cur_=" | ||
| + | ls=" | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | *:*) : great ;; | ||
| + | *) | ||
| + | esac | ||
| + | |||
| + | __gitcomp_file " | ||
| + | | sed ' | ||
| + | | ||
| + | " | ||
| + | ;; | ||
| + | *...*) | ||
| + | pfx=" | ||
| + | cur_=" | ||
| + | __git_complete_refs --pfx=" | ||
| + | ;; | ||
| + | *..*) | ||
| + | pfx=" | ||
| + | cur_=" | ||
| + | __git_complete_refs --pfx=" | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_complete_file () | ||
| + | { | ||
| + | __git_complete_revlist_file | ||
| + | } | ||
| + | |||
| + | __git_complete_revlist () | ||
| + | { | ||
| + | __git_complete_revlist_file | ||
| + | } | ||
| + | |||
| + | __git_complete_remote_or_refspec () | ||
| + | { | ||
| + | local cur_=" | ||
| + | local i c=$((__git_cmd_idx+1)) remote="" | ||
| + | if [ " | ||
| + | ((c++)) | ||
| + | fi | ||
| + | while [ $c -lt $cword ]; do | ||
| + | i=" | ||
| + | case " | ||
| + | --mirror) [ " | ||
| + | -d|--delete) [ " | ||
| + | --all) | ||
| + | case " | ||
| + | push) no_complete_refspec=1 ;; | ||
| + | fetch) | ||
| + | return | ||
| + | ;; | ||
| + | *) ;; | ||
| + | esac | ||
| + | ;; | ||
| + | --multiple) no_complete_refspec=1; | ||
| + | -*) ;; | ||
| + | *) remote=" | ||
| + | esac | ||
| + | ((c++)) | ||
| + | done | ||
| + | if [ -z " | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | fi | ||
| + | if [ $no_complete_refspec = 1 ]; then | ||
| + | return | ||
| + | fi | ||
| + | [ " | ||
| + | case " | ||
| + | *:*) | ||
| + | case " | ||
| + | *:*) : great ;; | ||
| + | *) | ||
| + | esac | ||
| + | cur_=" | ||
| + | lhs=0 | ||
| + | ;; | ||
| + | +*) | ||
| + | pfx=" | ||
| + | cur_=" | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | fetch) | ||
| + | if [ $lhs = 1 ]; then | ||
| + | __git_complete_fetch_refspecs " | ||
| + | else | ||
| + | __git_complete_refs --pfx=" | ||
| + | fi | ||
| + | ;; | ||
| + | pull|remote) | ||
| + | if [ $lhs = 1 ]; then | ||
| + | __git_complete_refs --remote=" | ||
| + | else | ||
| + | __git_complete_refs --pfx=" | ||
| + | fi | ||
| + | ;; | ||
| + | push) | ||
| + | if [ $lhs = 1 ]; then | ||
| + | __git_complete_refs --pfx=" | ||
| + | else | ||
| + | __git_complete_refs --remote=" | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_complete_strategy () | ||
| + | { | ||
| + | __git_compute_merge_strategies | ||
| + | case " | ||
| + | -s|--strategy) | ||
| + | __gitcomp " | ||
| + | return 0 | ||
| + | ;; | ||
| + | -X) | ||
| + | __gitcomp " | ||
| + | return 0 | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --strategy=*) | ||
| + | __gitcomp " | ||
| + | return 0 | ||
| + | ;; | ||
| + | --strategy-option=*) | ||
| + | __gitcomp " | ||
| + | return 0 | ||
| + | ;; | ||
| + | esac | ||
| + | return 1 | ||
| + | } | ||
| + | |||
| + | __git_all_commands= | ||
| + | __git_compute_all_commands () | ||
| + | { | ||
| + | test -n " | ||
| + | __git_all_commands=$(__git --list-cmds=main, | ||
| + | } | ||
| + | |||
| + | # Lists all set config variables starting with the given section prefix, | ||
| + | # with the prefix removed. | ||
| + | __git_get_config_variables () | ||
| + | { | ||
| + | local section=" | ||
| + | for i in $(__git config --name-only --get-regexp " | ||
| + | echo " | ||
| + | done | ||
| + | } | ||
| + | |||
| + | __git_pretty_aliases () | ||
| + | { | ||
| + | __git_get_config_variables " | ||
| + | } | ||
| + | |||
| + | # __git_aliased_command requires 1 argument | ||
| + | __git_aliased_command () | ||
| + | { | ||
| + | local cur=$1 last list= word cmdline | ||
| + | |||
| + | while [[ -n " | ||
| + | if [[ " | ||
| + | # loop detected | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | cmdline=$(__git config --get " | ||
| + | list=" | ||
| + | last=$cur | ||
| + | cur= | ||
| + | |||
| + | for word in $cmdline; do | ||
| + | case " | ||
| + | \!gitk|gitk) | ||
| + | cur=" | ||
| + | break | ||
| + | ;; | ||
| + | \!*) : shell command alias ;; | ||
| + | -*) : option ;; | ||
| + | *=*) : setting env ;; | ||
| + | git) : git itself ;; | ||
| + | \(\)) | ||
| + | {) : skip start of shell helper function ;; | ||
| + | :) : skip null command ;; | ||
| + | \' | ||
| + | *) | ||
| + | cur=" | ||
| + | break | ||
| + | esac | ||
| + | done | ||
| + | done | ||
| + | |||
| + | cur=$last | ||
| + | if [[ " | ||
| + | echo " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # Check whether one of the given words is present on the command line, | ||
| + | # and print the first word found. | ||
| + | # | ||
| + | # Usage: __git_find_on_cmdline [< | ||
| + | # --show-idx: Optionally show the index of the found word in the $words array. | ||
| + | __git_find_on_cmdline () | ||
| + | { | ||
| + | local word c=" | ||
| + | |||
| + | while test $# -gt 1; do | ||
| + | case " | ||
| + | --show-idx) show_idx=y ;; | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | local wordlist=" | ||
| + | |||
| + | while [ $c -lt $cword ]; do | ||
| + | for word in $wordlist; do | ||
| + | if [ " | ||
| + | if [ -n " | ||
| + | echo "$c $word" | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | return | ||
| + | fi | ||
| + | done | ||
| + | ((c++)) | ||
| + | done | ||
| + | } | ||
| + | |||
| + | # Similar to __git_find_on_cmdline, | ||
| + | # prints the *last* word found. Useful for finding which of two options that | ||
| + | # supersede each other came last, such as " | ||
| + | # | ||
| + | # Usage: __git_find_last_on_cmdline [< | ||
| + | # --show-idx: Optionally show the index of the found word in the $words array. | ||
| + | __git_find_last_on_cmdline () | ||
| + | { | ||
| + | local word c=$cword show_idx | ||
| + | |||
| + | while test $# -gt 1; do | ||
| + | case " | ||
| + | --show-idx) show_idx=y ;; | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | local wordlist=" | ||
| + | |||
| + | while [ $c -gt " | ||
| + | ((c--)) | ||
| + | for word in $wordlist; do | ||
| + | if [ " | ||
| + | if [ -n " | ||
| + | echo "$c $word" | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | return | ||
| + | fi | ||
| + | done | ||
| + | done | ||
| + | } | ||
| + | |||
| + | # Echo the value of an option set on the command line or config | ||
| + | # | ||
| + | # $1: short option name | ||
| + | # $2: long option name including = | ||
| + | # $3: list of possible values | ||
| + | # $4: config string (optional) | ||
| + | # | ||
| + | # example: | ||
| + | # result=" | ||
| + | # " | ||
| + | # | ||
| + | # result is then either empty (no option set) or " | ||
| + | # | ||
| + | # __git_get_option_value requires 3 arguments | ||
| + | __git_get_option_value () | ||
| + | { | ||
| + | local c short_opt long_opt val | ||
| + | local result= values config_key word | ||
| + | |||
| + | short_opt=" | ||
| + | long_opt=" | ||
| + | values=" | ||
| + | config_key=" | ||
| + | |||
| + | ((c = $cword - 1)) | ||
| + | while [ $c -ge 0 ]; do | ||
| + | word=" | ||
| + | for val in $values; do | ||
| + | if [ " | ||
| + | [ " | ||
| + | result=" | ||
| + | break 2 | ||
| + | fi | ||
| + | done | ||
| + | ((c--)) | ||
| + | done | ||
| + | |||
| + | if [ -n " | ||
| + | result=" | ||
| + | fi | ||
| + | |||
| + | echo " | ||
| + | } | ||
| + | |||
| + | __git_has_doubledash () | ||
| + | { | ||
| + | local c=1 | ||
| + | while [ $c -lt $cword ]; do | ||
| + | if [ " | ||
| + | return 0 | ||
| + | fi | ||
| + | ((c++)) | ||
| + | done | ||
| + | return 1 | ||
| + | } | ||
| + | |||
| + | # Try to count non option arguments passed on the command line for the | ||
| + | # specified git command. | ||
| + | # When options are used, it is necessary to use the special -- option to | ||
| + | # tell the implementation were non option arguments begin. | ||
| + | # XXX this can not be improved, since options can appear everywhere, as | ||
| + | # an example: | ||
| + | # git mv x -n y | ||
| + | # | ||
| + | # __git_count_arguments requires 1 argument: the git command executed. | ||
| + | __git_count_arguments () | ||
| + | { | ||
| + | local word i c=0 | ||
| + | |||
| + | # Skip " | ||
| + | for ((i=$__git_cmd_idx; | ||
| + | word=" | ||
| + | |||
| + | case " | ||
| + | --) | ||
| + | # Good; we can assume that the following are only non | ||
| + | # option arguments. | ||
| + | ((c = 0)) | ||
| + | ;; | ||
| + | " | ||
| + | # Skip the specified git command and discard git | ||
| + | # main options | ||
| + | ((c = 0)) | ||
| + | ;; | ||
| + | ?*) | ||
| + | ((c++)) | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | printf " | ||
| + | } | ||
| + | |||
| + | __git_whitespacelist=" | ||
| + | __git_patchformat=" | ||
| + | __git_showcurrentpatch=" | ||
| + | __git_am_inprogress_options=" | ||
| + | __git_quoted_cr=" | ||
| + | |||
| + | _git_am () | ||
| + | { | ||
| + | __git_find_repo_path | ||
| + | if [ -d " | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | case " | ||
| + | --whitespace=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --patch-format=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --show-current-patch=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --quoted-cr=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin am "" | ||
| + | " | ||
| + | return | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_apply () | ||
| + | { | ||
| + | case " | ||
| + | --whitespace=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin apply | ||
| + | return | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_add () | ||
| + | { | ||
| + | case " | ||
| + | --chmod=*) | ||
| + | __gitcomp "+x -x" "" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin add | ||
| + | return | ||
| + | esac | ||
| + | |||
| + | local complete_opt=" | ||
| + | if test -n " | ||
| + | then | ||
| + | complete_opt=" | ||
| + | fi | ||
| + | __git_complete_index_file " | ||
| + | } | ||
| + | |||
| + | _git_archive () | ||
| + | { | ||
| + | case " | ||
| + | --format=*) | ||
| + | __gitcomp "$(git archive --list)" | ||
| + | return | ||
| + | ;; | ||
| + | --remote=*) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin archive " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_file | ||
| + | } | ||
| + | |||
| + | _git_bisect () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | local subcommands=" | ||
| + | local subcommand=" | ||
| + | if [ -z " | ||
| + | __git_find_repo_path | ||
| + | if [ -f " | ||
| + | __gitcomp " | ||
| + | else | ||
| + | __gitcomp " | ||
| + | fi | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | bad|good|reset|skip|start) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | *) | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_ref_fieldlist=" | ||
| + | |||
| + | _git_branch () | ||
| + | { | ||
| + | local i c=" | ||
| + | |||
| + | while [ $c -lt $cword ]; do | ||
| + | i=" | ||
| + | case " | ||
| + | -d|-D|--delete|-m|-M|--move|-c|-C|--copy) | ||
| + | only_local_ref=" | ||
| + | -r|--remotes) | ||
| + | has_r=" | ||
| + | esac | ||
| + | ((c++)) | ||
| + | done | ||
| + | |||
| + | case " | ||
| + | --set-upstream-to=*) | ||
| + | __git_complete_refs --cur=" | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin branch | ||
| + | ;; | ||
| + | *) | ||
| + | if [ $only_local_ref = " | ||
| + | __gitcomp_direct " | ||
| + | else | ||
| + | __git_complete_refs | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_bundle () | ||
| + | { | ||
| + | local cmd=" | ||
| + | case " | ||
| + | $((__git_cmd_idx+1))) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | $((__git_cmd_idx+2))) | ||
| + | # looking for a file | ||
| + | ;; | ||
| + | *) | ||
| + | case " | ||
| + | create) | ||
| + | __git_complete_revlist | ||
| + | ;; | ||
| + | esac | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | # Helper function to decide whether or not we should enable DWIM logic for | ||
| + | # git-switch and git-checkout. | ||
| + | # | ||
| + | # To decide between the following rules in decreasing priority order: | ||
| + | # - the last provided of " | ||
| + | # | ||
| + | # - If checkout.guess is false, disable completion of DWIM logic. | ||
| + | # - If the --no-track option is provided, take this as a hint to disable the | ||
| + | # DWIM completion logic | ||
| + | # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion | ||
| + | # | ||
| + | # - Enable DWIM logic otherwise. | ||
| + | # | ||
| + | __git_checkout_default_dwim_mode () | ||
| + | { | ||
| + | local last_option dwim_opt=" | ||
| + | |||
| + | if [ " | ||
| + | dwim_opt="" | ||
| + | fi | ||
| + | |||
| + | # --no-track disables DWIM, but with lower priority than | ||
| + | # --guess/ | ||
| + | if [ -n " | ||
| + | dwim_opt="" | ||
| + | fi | ||
| + | |||
| + | # checkout.guess = false disables DWIM, but with lower priority than | ||
| + | # --guess/ | ||
| + | if [ " | ||
| + | dwim_opt="" | ||
| + | fi | ||
| + | |||
| + | # Find the last provided --guess or --no-guess | ||
| + | last_option=" | ||
| + | case " | ||
| + | --guess) | ||
| + | dwim_opt=" | ||
| + | ;; | ||
| + | --no-guess) | ||
| + | dwim_opt="" | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | echo " | ||
| + | } | ||
| + | |||
| + | _git_checkout () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | local dwim_opt=" | ||
| + | |||
| + | case " | ||
| + | -b|-B|--orphan) | ||
| + | # Complete local branches (and DWIM branch | ||
| + | # remote branch names) for an option argument | ||
| + | # specifying a new branch name. This is for | ||
| + | # convenience, | ||
| + | # possibly based on pre-existing branch names. | ||
| + | __git_complete_refs $dwim_opt --mode=" | ||
| + | return | ||
| + | ;; | ||
| + | *) | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --conflict=*) | ||
| + | __gitcomp "diff3 merge zdiff3" | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin checkout | ||
| + | ;; | ||
| + | *) | ||
| + | # At this point, we've already handled special completion for | ||
| + | # the arguments to -b/-B, and --orphan. There are 3 main | ||
| + | # things left we can possibly complete: | ||
| + | # 1) a start-point for -b/-B, -d/ | ||
| + | # 2) a remote head, for --track | ||
| + | # 3) an arbitrary reference, possibly including DWIM names | ||
| + | # | ||
| + | |||
| + | if [ -n " | ||
| + | __git_complete_refs --mode=" | ||
| + | elif [ -n " | ||
| + | __git_complete_refs --mode=" | ||
| + | else | ||
| + | __git_complete_refs $dwim_opt --mode=" | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_sequencer_inprogress_options=" | ||
| + | |||
| + | __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options | ||
| + | |||
| + | _git_cherry_pick () | ||
| + | { | ||
| + | if __git_pseudoref_exists CHERRY_PICK_HEAD; | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | __git_complete_strategy && return | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin cherry-pick "" | ||
| + | " | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_clean () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin clean | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # XXX should we check for -x option ? | ||
| + | __git_complete_index_file " | ||
| + | } | ||
| + | |||
| + | _git_clone () | ||
| + | { | ||
| + | case " | ||
| + | -c|--config) | ||
| + | __git_complete_config_variable_name_and_value | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --config=*) | ||
| + | __git_complete_config_variable_name_and_value \ | ||
| + | --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin clone | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_untracked_file_modes=" | ||
| + | |||
| + | __git_trailer_tokens () | ||
| + | { | ||
| + | __git config --name-only --get-regexp ' | ||
| + | } | ||
| + | |||
| + | _git_commit () | ||
| + | { | ||
| + | case " | ||
| + | -c|-C) | ||
| + | __git_complete_refs | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --cleanup=*) | ||
| + | __gitcomp " | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --reuse-message=*|--reedit-message=*|\ | ||
| + | --fixup=*|--squash=*) | ||
| + | __git_complete_refs --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | --untracked-files=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --trailer=*) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin commit | ||
| + | return | ||
| + | esac | ||
| + | |||
| + | if __git rev-parse --verify --quiet HEAD >/ | ||
| + | __git_complete_index_file " | ||
| + | else | ||
| + | # This is the first commit | ||
| + | __git_complete_index_file " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_describe () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin describe | ||
| + | return | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | __git_diff_algorithms=" | ||
| + | |||
| + | __git_diff_submodule_formats=" | ||
| + | |||
| + | __git_color_moved_opts=" | ||
| + | |||
| + | __git_color_moved_ws_opts=" | ||
| + | ignore-all-space allow-indentation-change" | ||
| + | |||
| + | __git_ws_error_highlight_opts=" | ||
| + | |||
| + | # Options for the diff machinery (diff, log, show, stash, range-diff, ...) | ||
| + | __git_diff_common_options=" | ||
| + | --patch-with-stat --name-only --name-status --color | ||
| + | --no-color --color-words --no-renames --check | ||
| + | --color-moved --color-moved= --no-color-moved | ||
| + | --color-moved-ws= --no-color-moved-ws | ||
| + | --full-index --binary --abbrev --diff-filter= | ||
| + | --find-copies --find-object --find-renames | ||
| + | --no-relative --relative | ||
| + | --find-copies-harder --ignore-cr-at-eol | ||
| + | --text --ignore-space-at-eol --ignore-space-change | ||
| + | --ignore-all-space --ignore-blank-lines --exit-code | ||
| + | --quiet --ext-diff --no-ext-diff --unified= | ||
| + | --no-prefix --src-prefix= --dst-prefix= | ||
| + | --inter-hunk-context= --function-context | ||
| + | --patience --histogram --minimal | ||
| + | --raw --word-diff --word-diff-regex= | ||
| + | --dirstat --dirstat= --dirstat-by-file | ||
| + | --dirstat-by-file= --cumulative | ||
| + | --diff-algorithm= --default-prefix | ||
| + | --submodule --submodule= --ignore-submodules | ||
| + | --indent-heuristic --no-indent-heuristic | ||
| + | --textconv --no-textconv --break-rewrites | ||
| + | --patch --no-patch --cc --combined-all-paths | ||
| + | --anchored= --compact-summary --ignore-matching-lines= | ||
| + | --irreversible-delete --line-prefix --no-stat | ||
| + | --output= --output-indicator-context= | ||
| + | --output-indicator-new= --output-indicator-old= | ||
| + | --ws-error-highlight= | ||
| + | --pickaxe-all --pickaxe-regex --patch-with-raw | ||
| + | " | ||
| + | |||
| + | # Options for diff/ | ||
| + | __git_diff_difftool_options=" | ||
| + | --base --ours --theirs --no-index --merge-base | ||
| + | --ita-invisible-in-index --ita-visible-in-index | ||
| + | $__git_diff_common_options" | ||
| + | |||
| + | _git_diff () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --diff-algorithm=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --submodule=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --color-moved=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --color-moved-ws=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --ws-error-highlight=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist_file | ||
| + | } | ||
| + | |||
| + | __git_mergetools_common=" | ||
| + | tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge | ||
| + | bc codecompare smerge | ||
| + | " | ||
| + | |||
| + | _git_difftool () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --tool=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin difftool " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist_file | ||
| + | } | ||
| + | |||
| + | __git_fetch_recurse_submodules=" | ||
| + | |||
| + | _git_fetch () | ||
| + | { | ||
| + | case " | ||
| + | --recurse-submodules=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --filter=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin fetch | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_remote_or_refspec | ||
| + | } | ||
| + | |||
| + | __git_format_patch_extra_options=" | ||
| + | --full-index --not --all --no-prefix --src-prefix= | ||
| + | --dst-prefix= --notes | ||
| + | " | ||
| + | |||
| + | _git_format_patch () | ||
| + | { | ||
| + | case " | ||
| + | --thread=*) | ||
| + | __gitcomp " | ||
| + | deep shallow | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --base=*|--interdiff=*|--range-diff=*) | ||
| + | __git_complete_refs --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin format-patch " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | _git_fsck () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin fsck | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_gitk () | ||
| + | { | ||
| + | __gitk_main | ||
| + | } | ||
| + | |||
| + | # Lists matching symbol names from a tag (as in ctags) file. | ||
| + | # 1: List symbol names matching this word. | ||
| + | # 2: The tag file to list symbol names from. | ||
| + | # 3: A prefix to be added to each listed symbol name (optional). | ||
| + | # 4: A suffix to be appended to each listed symbol name (optional). | ||
| + | __git_match_ctag () { | ||
| + | awk -v pfx=" | ||
| + | / | ||
| + | " " | ||
| + | } | ||
| + | |||
| + | # Complete symbol names from a tag file. | ||
| + | # Usage: __git_complete_symbol [< | ||
| + | # --tags=< | ||
| + | # default " | ||
| + | # --pfx=< | ||
| + | # --cur=< | ||
| + | # the current word to be completed. | ||
| + | # --sfx=< | ||
| + | # of the default space. | ||
| + | __git_complete_symbol () { | ||
| + | local tags=tags pfx="" | ||
| + | |||
| + | while test $# != 0; do | ||
| + | case " | ||
| + | --tags=*) tags=" | ||
| + | --pfx=*) pfx=" | ||
| + | --cur=*) cur_=" | ||
| + | --sfx=*) sfx=" | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | |||
| + | if test -r " | ||
| + | __gitcomp_direct " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_grep () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin grep | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | $((__git_cmd_idx+1)), | ||
| + | __git_complete_symbol && return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_help () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin help | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | if test -n " | ||
| + | then | ||
| + | __gitcomp " | ||
| + | else | ||
| + | __gitcomp " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_init () | ||
| + | { | ||
| + | case " | ||
| + | --shared=*) | ||
| + | __gitcomp " | ||
| + | false true umask group all world everybody | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin init | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_ls_files () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin ls-files | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # XXX ignore options like --modified and always suggest all cached | ||
| + | # files. | ||
| + | __git_complete_index_file " | ||
| + | } | ||
| + | |||
| + | _git_ls_remote () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin ls-remote | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __gitcomp_nl " | ||
| + | } | ||
| + | |||
| + | _git_ls_tree () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin ls-tree | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | __git_complete_file | ||
| + | } | ||
| + | |||
| + | # Options that go well for log, shortlog and gitk | ||
| + | __git_log_common_options=" | ||
| + | --not --all | ||
| + | --branches --tags --remotes | ||
| + | --first-parent --merges --no-merges | ||
| + | --max-count= | ||
| + | --max-age= --since= --after= | ||
| + | --min-age= --until= --before= | ||
| + | --min-parents= --max-parents= | ||
| + | --no-min-parents --no-max-parents | ||
| + | --alternate-refs --ancestry-path | ||
| + | --author-date-order --basic-regexp | ||
| + | --bisect --boundary --exclude-first-parent-only | ||
| + | --exclude-hidden --extended-regexp | ||
| + | --fixed-strings --grep-reflog | ||
| + | --ignore-missing --left-only --perl-regexp | ||
| + | --reflog --regexp-ignore-case --remove-empty | ||
| + | --right-only --show-linear-break | ||
| + | --show-notes-by-default --show-pulls | ||
| + | --since-as-filter --single-worktree | ||
| + | " | ||
| + | # Options that go well for log and gitk (not shortlog) | ||
| + | __git_log_gitk_options=" | ||
| + | --dense --sparse --full-history | ||
| + | --simplify-merges --simplify-by-decoration | ||
| + | --left-right --notes --no-notes | ||
| + | " | ||
| + | # Options that go well for log and shortlog (not gitk) | ||
| + | __git_log_shortlog_options=" | ||
| + | --author= --committer= --grep= | ||
| + | --all-match --invert-grep | ||
| + | " | ||
| + | # Options accepted by log and show | ||
| + | __git_log_show_options=" | ||
| + | --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff | ||
| + | --encoding= | ||
| + | " | ||
| + | |||
| + | __git_diff_merges_opts=" | ||
| + | |||
| + | __git_log_pretty_formats=" | ||
| + | __git_log_date_formats=" | ||
| + | |||
| + | _git_log () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | __git_find_repo_path | ||
| + | |||
| + | local merge="" | ||
| + | if __git_pseudoref_exists MERGE_HEAD; then | ||
| + | merge=" | ||
| + | fi | ||
| + | case " | ||
| + | -L,:*:*) | ||
| + | return # fall back to Bash filename completion | ||
| + | ;; | ||
| + | -L,:*) | ||
| + | __git_complete_symbol --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | -G,*|-S,*) | ||
| + | __git_complete_symbol | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --pretty=*|--format=*) | ||
| + | __gitcomp " | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --date=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --decorate=*) | ||
| + | __gitcomp "full short no" "" | ||
| + | return | ||
| + | ;; | ||
| + | --diff-algorithm=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --submodule=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --ws-error-highlight=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --no-walk=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --diff-merges=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | $__git_log_common_options | ||
| + | $__git_log_shortlog_options | ||
| + | $__git_log_gitk_options | ||
| + | $__git_log_show_options | ||
| + | --root --topo-order --date-order --reverse | ||
| + | --follow --full-diff | ||
| + | --abbrev-commit --no-abbrev-commit --abbrev= | ||
| + | --relative-date --date= | ||
| + | --pretty= --format= --oneline | ||
| + | --show-signature | ||
| + | --cherry-mark | ||
| + | --cherry-pick | ||
| + | --graph | ||
| + | --decorate --decorate= --no-decorate | ||
| + | --walk-reflogs | ||
| + | --no-walk --no-walk= --do-walk | ||
| + | --parents --children | ||
| + | --expand-tabs --expand-tabs= --no-expand-tabs | ||
| + | --clear-decorations --decorate-refs= | ||
| + | --decorate-refs-exclude= | ||
| + | $merge | ||
| + | $__git_diff_common_options | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | -L:*:*) | ||
| + | return # fall back to Bash filename completion | ||
| + | ;; | ||
| + | -L:*) | ||
| + | __git_complete_symbol --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | -G*) | ||
| + | __git_complete_symbol --pfx=" | ||
| + | return | ||
| + | ;; | ||
| + | -S*) | ||
| + | __git_complete_symbol --pfx=" | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | _git_merge () | ||
| + | { | ||
| + | __git_complete_strategy && return | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin merge | ||
| + | return | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_mergetool () | ||
| + | { | ||
| + | case " | ||
| + | --tool=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_merge_base () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin merge-base | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_mv () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin mv | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | if [ $(__git_count_arguments " | ||
| + | # We need to show both cached and untracked files (including | ||
| + | # empty directories) since this may not be the last argument. | ||
| + | __git_complete_index_file " | ||
| + | else | ||
| + | __git_complete_index_file " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_notes () | ||
| + | { | ||
| + | local subcommands=' | ||
| + | local subcommand=" | ||
| + | |||
| + | case " | ||
| + | ,--*) | ||
| + | __gitcomp_builtin notes | ||
| + | ;; | ||
| + | ,*) | ||
| + | case " | ||
| + | --ref) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | *) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | esac | ||
| + | ;; | ||
| + | *, | ||
| + | __git_complete_refs --cur=" | ||
| + | ;; | ||
| + | *,--*) | ||
| + | __gitcomp_builtin notes_$subcommand | ||
| + | ;; | ||
| + | prune, | ||
| + | # this command does not take a ref, do not complete it | ||
| + | ;; | ||
| + | *) | ||
| + | case " | ||
| + | -m|-F) | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | esac | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_pull () | ||
| + | { | ||
| + | __git_complete_strategy && return | ||
| + | |||
| + | case " | ||
| + | --recurse-submodules=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin pull | ||
| + | |||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_remote_or_refspec | ||
| + | } | ||
| + | |||
| + | __git_push_recurse_submodules=" | ||
| + | |||
| + | __git_complete_force_with_lease () | ||
| + | { | ||
| + | local cur_=$1 | ||
| + | |||
| + | case " | ||
| + | --*=) | ||
| + | ;; | ||
| + | *:*) | ||
| + | __git_complete_refs --cur=" | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_refs --cur=" | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_push () | ||
| + | { | ||
| + | case " | ||
| + | --repo) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | --recurse-submodules) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --repo=*) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | --recurse-submodules=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --force-with-lease=*) | ||
| + | __git_complete_force_with_lease " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin push | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_remote_or_refspec | ||
| + | } | ||
| + | |||
| + | _git_range_diff () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | --creation-factor= --no-dual-color | ||
| + | $__git_diff_common_options | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | __git_rebase_inprogress_options=" | ||
| + | __git_rebase_interactive_inprogress_options=" | ||
| + | |||
| + | _git_rebase () | ||
| + | { | ||
| + | __git_find_repo_path | ||
| + | if [ -f " | ||
| + | __gitcomp " | ||
| + | return | ||
| + | elif [ -d " | ||
| + | [ -d " | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | __git_complete_strategy && return | ||
| + | case " | ||
| + | --whitespace=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --onto=*) | ||
| + | __git_complete_refs --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin rebase "" | ||
| + | " | ||
| + | |||
| + | return | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_reflog () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | local subcommand=" | ||
| + | |||
| + | if [ -z " | ||
| + | __gitcomp " | ||
| + | else | ||
| + | __git_complete_refs | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | __git_send_email_confirm_options=" | ||
| + | __git_send_email_suppresscc_options=" | ||
| + | |||
| + | _git_send_email () | ||
| + | { | ||
| + | case " | ||
| + | --to|--cc|--bcc|--from) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --confirm=*) | ||
| + | __gitcomp " | ||
| + | $__git_send_email_confirm_options | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --suppress-cc=*) | ||
| + | __gitcomp " | ||
| + | $__git_send_email_suppresscc_options | ||
| + | " "" | ||
| + | |||
| + | return | ||
| + | ;; | ||
| + | --smtp-encryption=*) | ||
| + | __gitcomp "ssl tls" "" | ||
| + | return | ||
| + | ;; | ||
| + | --thread=*) | ||
| + | __gitcomp " | ||
| + | deep shallow | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --to=*|--cc=*|--bcc=*|--from=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin send-email " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | _git_stage () | ||
| + | { | ||
| + | _git_add | ||
| + | } | ||
| + | |||
| + | _git_status () | ||
| + | { | ||
| + | local complete_opt | ||
| + | local untracked_state | ||
| + | |||
| + | case " | ||
| + | --ignore-submodules=*) | ||
| + | __gitcomp "none untracked dirty all" "" | ||
| + | return | ||
| + | ;; | ||
| + | --untracked-files=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --column=*) | ||
| + | __gitcomp " | ||
| + | always never auto column row plain dense nodense | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin status | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | untracked_state=" | ||
| + | " | ||
| + | |||
| + | case " | ||
| + | no) | ||
| + | # --ignored option does not matter | ||
| + | complete_opt= | ||
| + | ;; | ||
| + | all|normal|*) | ||
| + | complete_opt=" | ||
| + | |||
| + | if [ -n " | ||
| + | complete_opt=" | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | __git_complete_index_file " | ||
| + | } | ||
| + | |||
| + | _git_switch () | ||
| + | { | ||
| + | local dwim_opt=" | ||
| + | |||
| + | case " | ||
| + | -c|-C|--orphan) | ||
| + | # Complete local branches (and DWIM branch | ||
| + | # remote branch names) for an option argument | ||
| + | # specifying a new branch name. This is for | ||
| + | # convenience, | ||
| + | # possibly based on pre-existing branch names. | ||
| + | __git_complete_refs $dwim_opt --mode=" | ||
| + | return | ||
| + | ;; | ||
| + | *) | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --conflict=*) | ||
| + | __gitcomp "diff3 merge zdiff3" | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin switch | ||
| + | ;; | ||
| + | *) | ||
| + | # Unlike in git checkout, git switch --orphan does not take | ||
| + | # a start point. Thus we really have nothing to complete after | ||
| + | # the branch name. | ||
| + | if [ -n " | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | # At this point, we've already handled special completion for | ||
| + | # -c/-C, and --orphan. There are 3 main things left to | ||
| + | # complete: | ||
| + | # 1) a start-point for -c/-C or -d/--detach | ||
| + | # 2) a remote head, for --track | ||
| + | # 3) a branch name, possibly including DWIM remote branches | ||
| + | |||
| + | if [ -n " | ||
| + | __git_complete_refs --mode=" | ||
| + | elif [ -n " | ||
| + | __git_complete_refs --mode=" | ||
| + | else | ||
| + | __git_complete_refs $dwim_opt --mode=" | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_config_get_set_variables () | ||
| + | { | ||
| + | local prevword word config_file= c=$cword | ||
| + | while [ $c -gt " | ||
| + | word=" | ||
| + | case " | ||
| + | --system|--global|--local|--file=*) | ||
| + | config_file=" | ||
| + | break | ||
| + | ;; | ||
| + | -f|--file) | ||
| + | config_file=" | ||
| + | break | ||
| + | ;; | ||
| + | esac | ||
| + | prevword=$word | ||
| + | c=$((--c)) | ||
| + | done | ||
| + | |||
| + | __git config $config_file --name-only --list | ||
| + | } | ||
| + | |||
| + | __git_config_vars= | ||
| + | __git_compute_config_vars () | ||
| + | { | ||
| + | test -n " | ||
| + | __git_config_vars=" | ||
| + | } | ||
| + | |||
| + | __git_config_sections= | ||
| + | __git_compute_config_sections () | ||
| + | { | ||
| + | test -n " | ||
| + | __git_config_sections=" | ||
| + | } | ||
| + | |||
| + | # Completes possible values of various configuration variables. | ||
| + | # | ||
| + | # Usage: __git_complete_config_variable_value [< | ||
| + | # --varname=< | ||
| + | # to be completed. | ||
| + | # | ||
| + | # --cur=< | ||
| + | # word to be completed. | ||
| + | __git_complete_config_variable_value () | ||
| + | { | ||
| + | local varname=" | ||
| + | |||
| + | while test $# != 0; do | ||
| + | case " | ||
| + | --varname=*) varname=" | ||
| + | --cur=*) cur_=" | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | |||
| + | if [ " | ||
| + | varname=" | ||
| + | else | ||
| + | varname=" | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | branch.*.remote|branch.*.pushremote) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | branch.*.merge) | ||
| + | __git_complete_refs --cur=" | ||
| + | return | ||
| + | ;; | ||
| + | branch.*.rebase) | ||
| + | __gitcomp "false true merges interactive" | ||
| + | return | ||
| + | ;; | ||
| + | remote.pushdefault) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | remote.*.fetch) | ||
| + | local remote=" | ||
| + | remote=" | ||
| + | if [ -z " | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | fi | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | remote.*.push) | ||
| + | local remote=" | ||
| + | remote=" | ||
| + | __gitcomp_nl " | ||
| + | --format=' | ||
| + | return | ||
| + | ;; | ||
| + | pull.twohead|pull.octopus) | ||
| + | __git_compute_merge_strategies | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | color.pager) | ||
| + | __gitcomp "false true" "" | ||
| + | return | ||
| + | ;; | ||
| + | color.*.*) | ||
| + | __gitcomp " | ||
| + | normal black red green yellow blue magenta cyan white | ||
| + | bold dim ul blink reverse | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | color.*) | ||
| + | __gitcomp "false true always never auto" "" | ||
| + | return | ||
| + | ;; | ||
| + | diff.submodule) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | help.format) | ||
| + | __gitcomp "man info web html" "" | ||
| + | return | ||
| + | ;; | ||
| + | log.date) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | sendemail.aliasfiletype) | ||
| + | __gitcomp "mutt mailrc pine elm gnus" "" | ||
| + | return | ||
| + | ;; | ||
| + | sendemail.confirm) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | sendemail.suppresscc) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | sendemail.transferencoding) | ||
| + | __gitcomp "7bit 8bit quoted-printable base64" | ||
| + | return | ||
| + | ;; | ||
| + | *.*) | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | # Completes configuration sections, subsections, | ||
| + | # | ||
| + | # Usage: __git_complete_config_variable_name [< | ||
| + | # --cur=< | ||
| + | # | ||
| + | # --sfx=< | ||
| + | # | ||
| + | # | ||
| + | __git_complete_config_variable_name () | ||
| + | { | ||
| + | local cur_=" | ||
| + | |||
| + | while test $# != 0; do | ||
| + | case " | ||
| + | --cur=*) cur_=" | ||
| + | --sfx=*) sfx=" | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | |||
| + | case " | ||
| + | branch.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | branch.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp_direct " | ||
| + | __gitcomp_nl_append $' | ||
| + | return | ||
| + | ;; | ||
| + | guitool.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp " | ||
| + | argPrompt cmd confirm needsFile noConsole noRescan | ||
| + | prompt revPrompt revUnmerged title | ||
| + | " " | ||
| + | return | ||
| + | ;; | ||
| + | difftool.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp "cmd path" " | ||
| + | return | ||
| + | ;; | ||
| + | man.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp "cmd path" " | ||
| + | return | ||
| + | ;; | ||
| + | mergetool.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp "cmd path trustExitCode" | ||
| + | return | ||
| + | ;; | ||
| + | pager.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __git_compute_all_commands | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | remote.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp " | ||
| + | url proxy fetch push mirror skipDefaultUpdate | ||
| + | receivepack uploadpack tagOpt pushurl | ||
| + | " " | ||
| + | return | ||
| + | ;; | ||
| + | remote.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp_nl " | ||
| + | __gitcomp_nl_append " | ||
| + | return | ||
| + | ;; | ||
| + | url.*.*) | ||
| + | local pfx=" | ||
| + | cur_=" | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | *.*) | ||
| + | __git_compute_config_vars | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | *) | ||
| + | __git_compute_config_sections | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | # Completes ' | ||
| + | # for 'git -c section.name=value' | ||
| + | # | ||
| + | # Usage: __git_complete_config_variable_name_and_value [< | ||
| + | # --cur=< | ||
| + | # | ||
| + | __git_complete_config_variable_name_and_value () | ||
| + | { | ||
| + | local cur_=" | ||
| + | |||
| + | while test $# != 0; do | ||
| + | case " | ||
| + | --cur=*) cur_=" | ||
| + | *) return 1 ;; | ||
| + | esac | ||
| + | shift | ||
| + | done | ||
| + | |||
| + | case " | ||
| + | *=*) | ||
| + | __git_complete_config_variable_value \ | ||
| + | --varname=" | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_config_variable_name --cur=" | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_config () | ||
| + | { | ||
| + | case " | ||
| + | --get|--get-all|--unset|--unset-all) | ||
| + | __gitcomp_nl " | ||
| + | return | ||
| + | ;; | ||
| + | *.*) | ||
| + | __git_complete_config_variable_value | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin config | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_config_variable_name | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_remote () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | add rename remove set-head set-branches | ||
| + | get-url set-url show prune update | ||
| + | " | ||
| + | local subcommand=" | ||
| + | if [ -z " | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin remote | ||
| + | ;; | ||
| + | *) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | esac | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | add,--*) | ||
| + | __gitcomp_builtin remote_add | ||
| + | ;; | ||
| + | add,*) | ||
| + | ;; | ||
| + | set-head, | ||
| + | __gitcomp_builtin remote_set-head | ||
| + | ;; | ||
| + | set-branches, | ||
| + | __gitcomp_builtin remote_set-branches | ||
| + | ;; | ||
| + | set-head, | ||
| + | __git_complete_remote_or_refspec | ||
| + | ;; | ||
| + | update, | ||
| + | __gitcomp_builtin remote_update | ||
| + | ;; | ||
| + | update,*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | set-url, | ||
| + | __gitcomp_builtin remote_set-url | ||
| + | ;; | ||
| + | get-url, | ||
| + | __gitcomp_builtin remote_get-url | ||
| + | ;; | ||
| + | prune,--*) | ||
| + | __gitcomp_builtin remote_prune | ||
| + | ;; | ||
| + | *) | ||
| + | __gitcomp_nl " | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_replace () | ||
| + | { | ||
| + | case " | ||
| + | --format=*) | ||
| + | __gitcomp "short medium long" "" | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin replace | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_rerere () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | local subcommand=" | ||
| + | if test -z " | ||
| + | then | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_reset () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin reset | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_restore () | ||
| + | { | ||
| + | case " | ||
| + | -s) | ||
| + | __git_complete_refs | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --conflict=*) | ||
| + | __gitcomp "diff3 merge zdiff3" | ||
| + | ;; | ||
| + | --source=*) | ||
| + | __git_complete_refs --cur=" | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp_builtin restore | ||
| + | ;; | ||
| + | *) | ||
| + | if __git_pseudoref_exists HEAD; then | ||
| + | __git_complete_index_file " | ||
| + | fi | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_revert_inprogress_options=$__git_sequencer_inprogress_options | ||
| + | |||
| + | _git_revert () | ||
| + | { | ||
| + | if __git_pseudoref_exists REVERT_HEAD; | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | __git_complete_strategy && return | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin revert "" | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_refs | ||
| + | } | ||
| + | |||
| + | _git_rm () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin rm | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | __git_complete_index_file " | ||
| + | } | ||
| + | |||
| + | _git_shortlog () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | $__git_log_common_options | ||
| + | $__git_log_shortlog_options | ||
| + | --numbered --summary --email | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | _git_show () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | case " | ||
| + | --pretty=*|--format=*) | ||
| + | __gitcomp " | ||
| + | " "" | ||
| + | return | ||
| + | ;; | ||
| + | --diff-algorithm=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --submodule=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --color-moved=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --color-moved-ws=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --ws-error-highlight=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --diff-merges=*) | ||
| + | __gitcomp " | ||
| + | return | ||
| + | ;; | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | --oneline --show-signature | ||
| + | --expand-tabs --expand-tabs= --no-expand-tabs | ||
| + | $__git_log_show_options | ||
| + | $__git_diff_common_options | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist_file | ||
| + | } | ||
| + | |||
| + | _git_show_branch () | ||
| + | { | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin show-branch | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | __gitcomp_directories () | ||
| + | { | ||
| + | local _tmp_dir _tmp_completions _found=0 | ||
| + | |||
| + | # Get the directory of the current token; this differs from dirname | ||
| + | # in that it keeps up to the final trailing slash. | ||
| + | # that's fine too. | ||
| + | [[ " | ||
| + | _tmp_dir=$BASH_REMATCH | ||
| + | |||
| + | # Find possible directory completions, | ||
| + | # de-quoting, and handling unusual characters. | ||
| + | while IFS= read -r -d $' | ||
| + | # If there are directory completions, | ||
| + | # with " | ||
| + | if [[ $c == " | ||
| + | COMPREPLY+=(" | ||
| + | _found=1 | ||
| + | fi | ||
| + | done < <(__git ls-tree -z -d --name-only HEAD $_tmp_dir) | ||
| + | |||
| + | if [[ $_found == 0 ]] && [[ " | ||
| + | # No possible further completions any deeper, so assume we're at | ||
| + | # a leaf directory and just consider it complete | ||
| + | __gitcomp_direct_append "$cur " | ||
| + | elif [[ $_found == 0 ]]; then | ||
| + | # No possible completions found. | ||
| + | # bash's default file and directory completion, because all | ||
| + | # valid completions have already been searched and the | ||
| + | # fallbacks can do nothing but mislead. | ||
| + | # mislead in three different ways: | ||
| + | # 1) Fallback file completion makes no sense when asking | ||
| + | # for directory completions, | ||
| + | # 2) Fallback directory completion is bad because | ||
| + | # e.g. "/ | ||
| + | # "/ | ||
| + | # 3) Fallback file/ | ||
| + | # on paths that exist in the current working tree, | ||
| + | # i.e. which are *already* part of their | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # " | ||
| + | # | ||
| + | COMPREPLY=( "" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # In non-cone mode, the arguments to {set,add} are supposed to be | ||
| + | # patterns, relative to the toplevel directory. | ||
| + | # of general pattern, like ' | ||
| + | # of those. | ||
| + | # presume that they are trying to provide a pattern that names a specific | ||
| + | # path. | ||
| + | __gitcomp_slash_leading_paths () | ||
| + | { | ||
| + | local dequoted_word pfx="" | ||
| + | |||
| + | # Since we are dealing with a sparse-checkout, | ||
| + | # exist in the local working copy. Therefore, we want to run all | ||
| + | # ls-files commands relative to the repository toplevel. | ||
| + | toplevel=" | ||
| + | |||
| + | __git_dequote " | ||
| + | |||
| + | # If the paths provided by the user already start with '/', | ||
| + | # they are considered relative to the toplevel of the repository | ||
| + | # already. | ||
| + | # them to start with the appropriate prefix. | ||
| + | case " | ||
| + | /*) | ||
| + | cur=" | ||
| + | ;; | ||
| + | *) | ||
| + | pfx=" | ||
| + | esac | ||
| + | |||
| + | # Since sparse-index is limited to cone-mode, in non-cone-mode the | ||
| + | # list of valid paths is precisely the cached files in the index. | ||
| + | # | ||
| + | # NEEDSWORK: | ||
| + | # 1) We probably need to take care of cases where ls-files | ||
| + | # responds with special quoting. | ||
| + | # 2) We probably need to take care of cases where ${cur} has | ||
| + | # some kind of special quoting. | ||
| + | # 3) On top of any quoting from 1 & 2, we have to provide an extra | ||
| + | # level of quoting for any paths that contain a ' | ||
| + | # ' | ||
| + | # interpreted by sparse-checkout as something other than a | ||
| + | # literal path character. | ||
| + | # Since there are two types of quoting here, this might get really | ||
| + | # complex. | ||
| + | completions=" | ||
| + | ls-files --cached -- " | ||
| + | | sed -e s%^%/% -e 's%$% %' | ||
| + | # Note, above, though that we needed all of the completions to be | ||
| + | # prefixed with a '/', | ||
| + | # completion will actually complete an entry and let us move on to | ||
| + | # the next one. | ||
| + | |||
| + | # Return what we've found. | ||
| + | if test -n " | ||
| + | # We found some completions; | ||
| + | local IFS=$' | ||
| + | COMPREPLY=($completions) | ||
| + | else | ||
| + | # Do NOT fall back to bash-style all-local-files-and-dirs | ||
| + | # when we find no match. | ||
| + | # useless: | ||
| + | # 1. "git sparse-checkout add" needs paths that are NOT | ||
| + | # currently in the working copy. "git | ||
| + | # sparse-checkout set" does as well, except in the | ||
| + | # special cases when users are only trying to narrow | ||
| + | # their sparse checkout to a subset of what they | ||
| + | # already have. | ||
| + | # | ||
| + | # 2. A path like ' | ||
| + | # the user wants all ' | ||
| + | # tree, or just the one under the current directory. | ||
| + | # It would result in a warning from the | ||
| + | # sparse-checkout command due to this. As such, all | ||
| + | # completions of paths should be prefixed with a | ||
| + | # '/' | ||
| + | # | ||
| + | # 3. We don't want paths prefixed with a '/' | ||
| + | # complete files in the system root directory, we | ||
| + | # want it to complete on files relative to the | ||
| + | # repository root. | ||
| + | # | ||
| + | # As such, make sure that NO completions are offered rather | ||
| + | # than falling back to bash's default completions. | ||
| + | COMPREPLY=( "" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_sparse_checkout () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | local subcommand=" | ||
| + | local using_cone=true | ||
| + | if [ -z " | ||
| + | __gitcomp " | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | *,--*) | ||
| + | __gitcomp_builtin sparse-checkout_$subcommand "" | ||
| + | ;; | ||
| + | set, | ||
| + | if [[ " | ||
| + | " | ||
| + | -z " | ||
| + | using_cone=false | ||
| + | fi | ||
| + | if [[ -n " | ||
| + | using_cone=false | ||
| + | fi | ||
| + | if [[ " | ||
| + | __gitcomp_directories | ||
| + | else | ||
| + | __gitcomp_slash_leading_paths | ||
| + | fi | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_stash () | ||
| + | { | ||
| + | local subcommands=' | ||
| + | local subcommand=" | ||
| + | |||
| + | if [ -z " | ||
| + | case " | ||
| + | *,--*) | ||
| + | __gitcomp_builtin stash_push | ||
| + | ;; | ||
| + | 1,sa*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | 1,*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | esac | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | list,--*) | ||
| + | # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() | ||
| + | __gitcomp_builtin stash_list " | ||
| + | ;; | ||
| + | show,--*) | ||
| + | __gitcomp_builtin stash_show " | ||
| + | ;; | ||
| + | *,--*) | ||
| + | __gitcomp_builtin " | ||
| + | ;; | ||
| + | branch,*) | ||
| + | if [ $cword -eq $((__git_cmd_idx+2)) ]; then | ||
| + | __git_complete_refs | ||
| + | else | ||
| + | __gitcomp_nl " | ||
| + | | sed -n -e ' | ||
| + | fi | ||
| + | ;; | ||
| + | show, | ||
| + | __gitcomp_nl " | ||
| + | | sed -n -e ' | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_submodule () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | local subcommands=" | ||
| + | local subcommand=" | ||
| + | if [ -z " | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | *) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | esac | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | case " | ||
| + | add,--*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | status, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | deinit, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | update, | ||
| + | __gitcomp " | ||
| + | --init --remote --no-fetch | ||
| + | --recommend-shallow --no-recommend-shallow | ||
| + | --force --rebase --merge --reference --depth --recursive --jobs | ||
| + | " | ||
| + | ;; | ||
| + | set-branch, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | summary, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | foreach, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | *) | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_svn () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | init fetch clone rebase dcommit log find-rev | ||
| + | set-tree commit-diff info create-ignore propget | ||
| + | proplist show-ignore show-externals branch tag blame | ||
| + | migrate mkdirs reset gc | ||
| + | " | ||
| + | local subcommand=" | ||
| + | if [ -z " | ||
| + | __gitcomp " | ||
| + | else | ||
| + | local remote_opts=" | ||
| + | local fc_opts=" | ||
| + | --follow-parent --authors-file= --repack= | ||
| + | --no-metadata --use-svm-props --use-svnsync-props | ||
| + | --log-window-size= --no-checkout --quiet | ||
| + | --repack-flags --use-log-author --localtime | ||
| + | --add-author-from | ||
| + | --recursive | ||
| + | --ignore-paths= --include-paths= $remote_opts | ||
| + | " | ||
| + | local init_opts=" | ||
| + | --template= --shared= --trunk= --tags= | ||
| + | --branches= --stdlayout --minimize-url | ||
| + | --no-metadata --use-svm-props --use-svnsync-props | ||
| + | --rewrite-root= --prefix= $remote_opts | ||
| + | " | ||
| + | local cmt_opts=" | ||
| + | --edit --rmdir --find-copies-harder --copy-similarity= | ||
| + | " | ||
| + | |||
| + | case " | ||
| + | fetch, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | clone, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | init,--*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | dcommit, | ||
| + | __gitcomp " | ||
| + | --merge --strategy= --verbose --dry-run | ||
| + | --fetch-all --no-rebase --commit-url | ||
| + | --revision --interactive $cmt_opts $fc_opts | ||
| + | " | ||
| + | ;; | ||
| + | set-tree, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | create-ignore, | ||
| + | show-externals, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | log,--*) | ||
| + | __gitcomp " | ||
| + | --limit= --revision= --verbose --incremental | ||
| + | --oneline --show-commit --non-recursive | ||
| + | --authors-file= --color | ||
| + | " | ||
| + | ;; | ||
| + | rebase, | ||
| + | __gitcomp " | ||
| + | --merge --verbose --strategy= --local | ||
| + | --fetch-all --dry-run $fc_opts | ||
| + | " | ||
| + | ;; | ||
| + | commit-diff, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | info,--*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | branch, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | tag,--*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | blame, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | migrate, | ||
| + | __gitcomp " | ||
| + | --config-dir= --ignore-paths= --minimize | ||
| + | --no-auth-cache --username= | ||
| + | " | ||
| + | ;; | ||
| + | reset, | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | *) | ||
| + | ;; | ||
| + | esac | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | _git_tag () | ||
| + | { | ||
| + | local i c=" | ||
| + | while [ $c -lt $cword ]; do | ||
| + | i=" | ||
| + | case " | ||
| + | -d|--delete|-v|--verify) | ||
| + | __gitcomp_direct " | ||
| + | return | ||
| + | ;; | ||
| + | -f) | ||
| + | f=1 | ||
| + | ;; | ||
| + | esac | ||
| + | ((c++)) | ||
| + | done | ||
| + | |||
| + | case " | ||
| + | -m|-F) | ||
| + | ;; | ||
| + | -*|tag) | ||
| + | if [ $f = 1 ]; then | ||
| + | __gitcomp_direct " | ||
| + | fi | ||
| + | ;; | ||
| + | *) | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin tag | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | _git_whatchanged () | ||
| + | { | ||
| + | _git_log | ||
| + | } | ||
| + | |||
| + | __git_complete_worktree_paths () | ||
| + | { | ||
| + | local IFS=$' | ||
| + | # Generate completion reply from worktree list skipping the first | ||
| + | # entry: it's the path of the main worktree, which can't be moved, | ||
| + | # removed, locked, etc. | ||
| + | __gitcomp_nl "$(git worktree list --porcelain | | ||
| + | sed -n -e '2,$ s/^worktree // | ||
| + | } | ||
| + | |||
| + | _git_worktree () | ||
| + | { | ||
| + | local subcommands=" | ||
| + | local subcommand subcommand_idx | ||
| + | |||
| + | subcommand=" | ||
| + | subcommand_idx=" | ||
| + | subcommand=" | ||
| + | |||
| + | case " | ||
| + | ,*) | ||
| + | __gitcomp " | ||
| + | ;; | ||
| + | *,--*) | ||
| + | __gitcomp_builtin worktree_$subcommand | ||
| + | ;; | ||
| + | add,*) # usage: git worktree add [< | ||
| + | # Here we are not completing an --option, it's either the | ||
| + | # path or a ref. | ||
| + | case " | ||
| + | -b|-B) # Complete refs for branch to be created/ | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | -*) # The previous word is an -o|--option without an | ||
| + | # unstuck argument: have to complete the path for | ||
| + | # the new worktree, so don't list anything, but let | ||
| + | # Bash fall back to filename completion. | ||
| + | ;; | ||
| + | *) # The previous word is not an --option, so it must | ||
| + | # be either the ' | ||
| + | # argument of an option (e.g. branch for -b|-B), or | ||
| + | # the path for the new worktree. | ||
| + | if [ $cword -eq $((subcommand_idx+1)) ]; then | ||
| + | # Right after the ' | ||
| + | # complete the path, so fall back to Bash | ||
| + | # filename completion. | ||
| + | : | ||
| + | else | ||
| + | case " | ||
| + | -b|-B) # | ||
| + | # complete the path, so fall back | ||
| + | # to Bash filename completion. | ||
| + | ;; | ||
| + | *) # After the path: have to complete | ||
| + | # the ref to be checked out. | ||
| + | __git_complete_refs | ||
| + | ;; | ||
| + | esac | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | ;; | ||
| + | lock, | ||
| + | __git_complete_worktree_paths | ||
| + | ;; | ||
| + | move,*) | ||
| + | if [ $cword -eq $((subcommand_idx+1)) ]; then | ||
| + | # The first parameter must be an existing working | ||
| + | # tree to be moved. | ||
| + | __git_complete_worktree_paths | ||
| + | else | ||
| + | # The second parameter is the destination: | ||
| + | # be any path, so don't list anything, but let Bash | ||
| + | # fall back to filename completion. | ||
| + | : | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_complete_common () { | ||
| + | local command=" | ||
| + | |||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp_builtin " | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_cmds_with_parseopt_helper= | ||
| + | __git_support_parseopt_helper () { | ||
| + | test -n " | ||
| + | __git_cmds_with_parseopt_helper=" | ||
| + | |||
| + | case " $__git_cmds_with_parseopt_helper " in | ||
| + | *" $1 "*) | ||
| + | return 0 | ||
| + | ;; | ||
| + | *) | ||
| + | return 1 | ||
| + | ;; | ||
| + | esac | ||
| + | } | ||
| + | |||
| + | __git_have_func () { | ||
| + | declare -f -- " | ||
| + | } | ||
| + | |||
| + | __git_complete_command () { | ||
| + | local command=" | ||
| + | local completion_func=" | ||
| + | if ! __git_have_func $completion_func && | ||
| + | __git_have_func _completion_loader | ||
| + | then | ||
| + | _completion_loader " | ||
| + | fi | ||
| + | if __git_have_func $completion_func | ||
| + | then | ||
| + | $completion_func | ||
| + | return 0 | ||
| + | elif __git_support_parseopt_helper " | ||
| + | then | ||
| + | __git_complete_common " | ||
| + | return 0 | ||
| + | else | ||
| + | return 1 | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | __git_main () | ||
| + | { | ||
| + | local i c=1 command __git_dir __git_repo_path | ||
| + | local __git_C_args C_args_count=0 | ||
| + | local __git_cmd_idx | ||
| + | |||
| + | while [ $c -lt $cword ]; do | ||
| + | i=" | ||
| + | case " | ||
| + | --git-dir=*) | ||
| + | __git_dir=" | ||
| + | ;; | ||
| + | --git-dir) | ||
| + | ((c++)) | ||
| + | __git_dir=" | ||
| + | ;; | ||
| + | --bare) | ||
| + | __git_dir=" | ||
| + | ;; | ||
| + | --help) | ||
| + | command=" | ||
| + | break | ||
| + | ;; | ||
| + | -c|--work-tree|--namespace) | ||
| + | ((c++)) | ||
| + | ;; | ||
| + | -C) | ||
| + | __git_C_args[C_args_count++]=-C | ||
| + | ((c++)) | ||
| + | __git_C_args[C_args_count++]=" | ||
| + | ;; | ||
| + | -*) | ||
| + | ;; | ||
| + | *) | ||
| + | command=" | ||
| + | __git_cmd_idx=" | ||
| + | break | ||
| + | ;; | ||
| + | esac | ||
| + | ((c++)) | ||
| + | done | ||
| + | |||
| + | if [ -z " | ||
| + | case " | ||
| + | --git-dir|-C|--work-tree) | ||
| + | # these need a path argument, let's fall back to | ||
| + | # Bash filename completion | ||
| + | return | ||
| + | ;; | ||
| + | -c) | ||
| + | __git_complete_config_variable_name_and_value | ||
| + | return | ||
| + | ;; | ||
| + | --namespace) | ||
| + | # we don't support completing these options' | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | --paginate | ||
| + | --no-pager | ||
| + | --git-dir= | ||
| + | --bare | ||
| + | --version | ||
| + | --exec-path | ||
| + | --exec-path= | ||
| + | --html-path | ||
| + | --man-path | ||
| + | --info-path | ||
| + | --work-tree= | ||
| + | --namespace= | ||
| + | --no-replace-objects | ||
| + | --help | ||
| + | " | ||
| + | ;; | ||
| + | *) | ||
| + | if test -n " | ||
| + | then | ||
| + | __gitcomp " | ||
| + | else | ||
| + | local list_cmds=list-mainporcelain, | ||
| + | |||
| + | if test " | ||
| + | then | ||
| + | list_cmds=builtins, | ||
| + | fi | ||
| + | __gitcomp " | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | __git_complete_command " | ||
| + | |||
| + | local expansion=$(__git_aliased_command " | ||
| + | if [ -n " | ||
| + | words[1]=$expansion | ||
| + | __git_complete_command " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | __gitk_main () | ||
| + | { | ||
| + | __git_has_doubledash && return | ||
| + | |||
| + | local __git_repo_path | ||
| + | __git_find_repo_path | ||
| + | |||
| + | local merge="" | ||
| + | if __git_pseudoref_exists MERGE_HEAD; then | ||
| + | merge=" | ||
| + | fi | ||
| + | case " | ||
| + | --*) | ||
| + | __gitcomp " | ||
| + | $__git_log_common_options | ||
| + | $__git_log_gitk_options | ||
| + | $merge | ||
| + | " | ||
| + | return | ||
| + | ;; | ||
| + | esac | ||
| + | __git_complete_revlist | ||
| + | } | ||
| + | |||
| + | if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then | ||
| + | echo " | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | __git_func_wrap () | ||
| + | { | ||
| + | local cur words cword prev | ||
| + | local __git_cmd_idx=0 | ||
| + | _get_comp_words_by_ref -n =: cur words cword prev | ||
| + | $1 | ||
| + | } | ||
| + | |||
| + | ___git_complete () | ||
| + | { | ||
| + | local wrapper=" | ||
| + | eval " | ||
| + | complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/ | ||
| + | || complete -o default -o nospace -F $wrapper $1 | ||
| + | } | ||
| + | |||
| + | # Setup the completion for git commands | ||
| + | # 1: command or alias | ||
| + | # 2: function to call (e.g. `git`, `gitk`, `git_fetch`) | ||
| + | __git_complete () | ||
| + | { | ||
| + | local func | ||
| + | |||
| + | if __git_have_func $2; then | ||
| + | func=$2 | ||
| + | elif __git_have_func __$2_main; then | ||
| + | func=__$2_main | ||
| + | elif __git_have_func _$2; then | ||
| + | func=_$2 | ||
| + | else | ||
| + | echo " | ||
| + | return 1 | ||
| + | fi | ||
| + | ___git_complete $1 $func | ||
| + | } | ||
| + | |||
| + | ___git_complete git __git_main | ||
| + | ___git_complete gitk __gitk_main | ||
| + | |||
| + | # The following are necessary only for Cygwin, and only are needed | ||
| + | # when the user has tab-completed the executable name and consequently | ||
| + | # included the ' | ||
| + | # | ||
| + | if [ " | ||
| + | ___git_complete git.exe __git_main | ||
| + | fi | ||
| + | </ | ||
| + | |||
| + | ==== git-prompt.sh ==== | ||
| + | <code bash git-prompt.sh> | ||
| + | # bash/zsh git prompt support | ||
| + | # | ||
| + | # Copyright (C) 2006,2007 Shawn O. Pearce < | ||
| + | # Distributed under the GNU General Public License, version 2.0. | ||
| + | # | ||
| + | # This script allows you to see repository status in your prompt. | ||
| + | # | ||
| + | # To enable: | ||
| + | # | ||
| + | # 1) Copy this file to somewhere (e.g. ~/ | ||
| + | # 2) Add the following line to your .bashrc/ | ||
| + | # source ~/ | ||
| + | # 3a) Change your PS1 to call __git_ps1 as | ||
| + | # command-substitution: | ||
| + | # Bash: PS1=' | ||
| + | # ZSH: setopt PROMPT_SUBST ; PS1=' | ||
| + | # the optional argument will be used as format string. | ||
| + | # 3b) Alternatively, | ||
| + | # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh | ||
| + | # with two parameters, <pre> and < | ||
| + | # you would put in $PS1 before and after the status string | ||
| + | # generated by the git-prompt machinery. | ||
| + | # Bash: PROMPT_COMMAND=' | ||
| + | # will show username, at-sign, host, colon, cwd, then | ||
| + | # various status string, followed by dollar and SP, as | ||
| + | # your prompt. | ||
| + | # ZSH: precmd () { __git_ps1 " | ||
| + | # will show username, pipe, then various status string, | ||
| + | # followed by colon, cwd, dollar and SP, as your prompt. | ||
| + | # Optionally, you can supply a third argument with a printf | ||
| + | # format string to finetune the output of the branch status | ||
| + | # | ||
| + | # The repository status will be displayed only if you are currently in a | ||
| + | # git repository. The %s token is the placeholder for the shown status. | ||
| + | # | ||
| + | # The prompt status always includes the current branch name. | ||
| + | # | ||
| + | # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value, | ||
| + | # unstaged (*) and staged (+) changes will be shown next to the branch | ||
| + | # name. You can configure this per-repository with the | ||
| + | # bash.showDirtyState variable, which defaults to true once | ||
| + | # GIT_PS1_SHOWDIRTYSTATE is enabled. | ||
| + | # | ||
| + | # You can also see if currently something is stashed, by setting | ||
| + | # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed, | ||
| + | # then a ' | ||
| + | # | ||
| + | # If you would like to see if there' | ||
| + | # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there' | ||
| + | # files, then a ' | ||
| + | # configure this per-repository with the bash.showUntrackedFiles | ||
| + | # variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is | ||
| + | # enabled. | ||
| + | # | ||
| + | # If you would like to see the difference between HEAD and its upstream, | ||
| + | # set GIT_PS1_SHOWUPSTREAM=" | ||
| + | # indicates you are ahead, "<>" | ||
| + | # indicates that there is no difference. You can further control | ||
| + | # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list | ||
| + | # of values: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # By default, __git_ps1 will compare HEAD to your SVN upstream if it can | ||
| + | # find one, or @{upstream} otherwise. | ||
| + | # GIT_PS1_SHOWUPSTREAM, | ||
| + | # setting the bash.showUpstream config variable. | ||
| + | # | ||
| + | # You can change the separator between the branch name and the above | ||
| + | # state symbols by setting GIT_PS1_STATESEPARATOR. The default separator | ||
| + | # is SP. | ||
| + | # | ||
| + | # When there is an in-progress operation such as a merge, rebase, | ||
| + | # revert, cherry-pick, | ||
| + | # related to the operation, often in the form " | ||
| + | # | ||
| + | # When the repository has a sparse-checkout, | ||
| + | # " | ||
| + | # single '?' | ||
| + | # by setting GIT_PS1_OMITSPARSESTATE. | ||
| + | # | ||
| + | # If you would like to see a notification on the prompt when there are | ||
| + | # unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to " | ||
| + | # prompt will include " | ||
| + | # | ||
| + | # If you would like to see more information about the identity of | ||
| + | # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE | ||
| + | # to one of these values: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # If you would like a colored hint about the current dirty state, set | ||
| + | # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on | ||
| + | # the colored output of "git status -sb". | ||
| + | # | ||
| + | # If you would like __git_ps1 to do nothing in the case when the current | ||
| + | # directory is set up to be ignored by git, then set | ||
| + | # GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the | ||
| + | # repository level by setting bash.hideIfPwdIgnored to " | ||
| + | |||
| + | # check whether printf supports -v | ||
| + | __git_printf_supports_v= | ||
| + | printf -v __git_printf_supports_v -- ' | ||
| + | |||
| + | # stores the divergence from upstream in $p | ||
| + | # used by GIT_PS1_SHOWUPSTREAM | ||
| + | __git_ps1_show_upstream () | ||
| + | { | ||
| + | local key value | ||
| + | local svn_remote svn_url_pattern count n | ||
| + | local upstream_type=git legacy="" | ||
| + | |||
| + | svn_remote=() | ||
| + | # get some config options from git-config | ||
| + | local output=" | ||
| + | while read -r key value; do | ||
| + | case " | ||
| + | bash.showupstream) | ||
| + | GIT_PS1_SHOWUPSTREAM=" | ||
| + | if [[ -z " | ||
| + | p="" | ||
| + | return | ||
| + | fi | ||
| + | ;; | ||
| + | svn-remote.*.url) | ||
| + | svn_remote[$((${# | ||
| + | svn_url_pattern=" | ||
| + | upstream_type=svn+git # default upstream type is SVN if available, else git | ||
| + | ;; | ||
| + | esac | ||
| + | done <<< | ||
| + | |||
| + | # parse configuration values | ||
| + | local option | ||
| + | for option in ${GIT_PS1_SHOWUPSTREAM}; | ||
| + | case " | ||
| + | git|svn) upstream_type=" | ||
| + | verbose) verbose=1 ;; | ||
| + | legacy) | ||
| + | name) | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | # Find our upstream type | ||
| + | case " | ||
| + | git) upstream_type=" | ||
| + | svn*) | ||
| + | # get the upstream from the " | ||
| + | # (git-svn uses essentially the same procedure internally) | ||
| + | local -a svn_upstream | ||
| + | svn_upstream=($(git log --first-parent -1 \ | ||
| + | --grep=" | ||
| + | if [[ 0 -ne ${# | ||
| + | svn_upstream=${svn_upstream[${# | ||
| + | svn_upstream=${svn_upstream%@*} | ||
| + | local n_stop=" | ||
| + | for ((n=1; n <= n_stop; n++)); do | ||
| + | svn_upstream=${svn_upstream# | ||
| + | done | ||
| + | |||
| + | if [[ -z " | ||
| + | # default branch name for checkouts with no layout: | ||
| + | upstream_type=${GIT_SVN_ID: | ||
| + | else | ||
| + | upstream_type=${svn_upstream#/ | ||
| + | fi | ||
| + | elif [[ " | ||
| + | upstream_type=" | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # Find how many commits we are ahead/ | ||
| + | if [[ -z " | ||
| + | count=" | ||
| + | " | ||
| + | else | ||
| + | # produce equivalent output to --count for older versions of git | ||
| + | local commits | ||
| + | if commits=" | ||
| + | then | ||
| + | local commit behind=0 ahead=0 | ||
| + | for commit in $commits | ||
| + | do | ||
| + | case " | ||
| + | "<" | ||
| + | *) | ||
| + | esac | ||
| + | done | ||
| + | count=" | ||
| + | else | ||
| + | count="" | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | # calculate the result | ||
| + | if [[ -z " | ||
| + | case " | ||
| + | "" | ||
| + | p="" | ||
| + | " | ||
| + | p=" | ||
| + | " | ||
| + | p=">" | ||
| + | *" | ||
| + | p="<" | ||
| + | *) # diverged from upstream | ||
| + | p="<>" | ||
| + | esac | ||
| + | else # verbose, set upstream instead of p | ||
| + | case " | ||
| + | "" | ||
| + | upstream="" | ||
| + | " | ||
| + | upstream=" | ||
| + | " | ||
| + | upstream=" | ||
| + | *" | ||
| + | upstream=" | ||
| + | *) # diverged from upstream | ||
| + | upstream=" | ||
| + | esac | ||
| + | if [[ -n " | ||
| + | __git_ps1_upstream_name=$(git rev-parse \ | ||
| + | --abbrev-ref " | ||
| + | if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then | ||
| + | upstream=" | ||
| + | else | ||
| + | upstream=" | ||
| + | # not needed anymore; keep user's | ||
| + | # environment clean | ||
| + | unset __git_ps1_upstream_name | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | } | ||
| + | |||
| + | # Helper function that is meant to be called from __git_ps1. | ||
| + | # injects color codes into the appropriate gitstring variables used | ||
| + | # to build a gitstring. Colored variables are responsible for clearing | ||
| + | # their own color. | ||
| + | __git_ps1_colorize_gitstring () | ||
| + | { | ||
| + | if [[ -n ${ZSH_VERSION-} ]]; then | ||
| + | local c_red=' | ||
| + | local c_green=' | ||
| + | local c_lblue=' | ||
| + | local c_clear=' | ||
| + | else | ||
| + | # Using \001 and \002 around colors is necessary to prevent | ||
| + | # issues with command line editing/ | ||
| + | local c_red=$' | ||
| + | local c_green=$' | ||
| + | local c_lblue=$' | ||
| + | local c_clear=$' | ||
| + | fi | ||
| + | local bad_color=$c_red | ||
| + | local ok_color=$c_green | ||
| + | local flags_color=" | ||
| + | |||
| + | local branch_color="" | ||
| + | if [ $detached = no ]; then | ||
| + | branch_color=" | ||
| + | else | ||
| + | branch_color=" | ||
| + | fi | ||
| + | if [ -n " | ||
| + | c=" | ||
| + | fi | ||
| + | b=" | ||
| + | |||
| + | if [ -n " | ||
| + | w=" | ||
| + | fi | ||
| + | if [ -n " | ||
| + | i=" | ||
| + | fi | ||
| + | if [ -n " | ||
| + | s=" | ||
| + | fi | ||
| + | if [ -n " | ||
| + | u=" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # Helper function to read the first line of a file into a variable. | ||
| + | # __git_eread requires 2 arguments, the file path and the name of the | ||
| + | # variable, in that order. | ||
| + | __git_eread () | ||
| + | { | ||
| + | test -r " | ||
| + | } | ||
| + | |||
| + | # see if a cherry-pick or revert is in progress, if the user has committed a | ||
| + | # conflict resolution with 'git commit' | ||
| + | # reverts then CHERRY_PICK_HEAD/ | ||
| + | # the todo file. | ||
| + | __git_sequencer_status () | ||
| + | { | ||
| + | local todo | ||
| + | if test -f " | ||
| + | then | ||
| + | r=" | ||
| + | return 0; | ||
| + | elif test -f " | ||
| + | then | ||
| + | r=" | ||
| + | return 0; | ||
| + | elif __git_eread " | ||
| + | then | ||
| + | case " | ||
| + | p[\ \ ]|pick[\ \ ]*) | ||
| + | r=" | ||
| + | return 0 | ||
| + | ;; | ||
| + | revert[\ \ ]*) | ||
| + | r=" | ||
| + | return 0 | ||
| + | ;; | ||
| + | esac | ||
| + | fi | ||
| + | return 1 | ||
| + | } | ||
| + | |||
| + | # __git_ps1 accepts 0 or 1 arguments (i.e., format string) | ||
| + | # when called from PS1 using command substitution | ||
| + | # in this mode it prints text to add to bash PS1 prompt (includes branch name) | ||
| + | # | ||
| + | # __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc) | ||
| + | # in that case it _sets_ PS1. The arguments are parts of a PS1 string. | ||
| + | # when two arguments are given, the first is prepended and the second appended | ||
| + | # to the state string when assigned to PS1. | ||
| + | # The optional third parameter will be used as printf format string to further | ||
| + | # customize the output of the git-status string. | ||
| + | # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true | ||
| + | __git_ps1 () | ||
| + | { | ||
| + | # preserve exit status | ||
| + | local exit=$? | ||
| + | local pcmode=no | ||
| + | local detached=no | ||
| + | local ps1pc_start=' | ||
| + | local ps1pc_end=' | ||
| + | local printf_format=' | ||
| + | |||
| + | case " | ||
| + | 2|3) pcmode=yes | ||
| + | ps1pc_start=" | ||
| + | ps1pc_end=" | ||
| + | printf_format=" | ||
| + | # set PS1 to a plain prompt so that we can | ||
| + | # simply return early if the prompt should not | ||
| + | # be decorated | ||
| + | PS1=" | ||
| + | ;; | ||
| + | 0|1) printf_format=" | ||
| + | ;; | ||
| + | *) return $exit | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # ps1_expanded: | ||
| + | # subjects the value of PS1 to parameter expansion: | ||
| + | # | ||
| + | # * bash does unless the promptvars option is disabled | ||
| + | # * zsh does not unless the PROMPT_SUBST option is set | ||
| + | # * POSIX shells always do | ||
| + | # | ||
| + | # If the shell would expand the contents of PS1 when drawing | ||
| + | # the prompt, a raw ref name must not be included in PS1. | ||
| + | # This protects the user from arbitrary code execution via | ||
| + | # specially crafted ref names. | ||
| + | # ' | ||
| + | # shell to execute 'sudo rm -rf /' when the prompt is drawn. | ||
| + | # | ||
| + | # Instead, the ref name should be placed in a separate global | ||
| + | # variable (in the __git_ps1_* namespace to avoid colliding | ||
| + | # with the user's environment) and that variable should be | ||
| + | # referenced from PS1. For example: | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # If the shell does not expand the contents of PS1, the raw | ||
| + | # ref name must be included in PS1. | ||
| + | # | ||
| + | # The value of this variable is only relevant when in pcmode. | ||
| + | # | ||
| + | # Assume that the shell follows the POSIX specification and | ||
| + | # expands PS1 unless determined otherwise. | ||
| + | # likely to be correct if the user has a non-bash, non-zsh | ||
| + | # shell and safer than the alternative if the assumption is | ||
| + | # incorrect.) | ||
| + | # | ||
| + | local ps1_expanded=yes | ||
| + | [ -z " | ||
| + | [ -z " | ||
| + | |||
| + | local repo_info rev_parse_exit_code | ||
| + | repo_info=" | ||
| + | --is-bare-repository --is-inside-work-tree --show-ref-format \ | ||
| + | --short HEAD 2>/ | ||
| + | rev_parse_exit_code=" | ||
| + | |||
| + | if [ -z " | ||
| + | return $exit | ||
| + | fi | ||
| + | |||
| + | local short_sha="" | ||
| + | if [ " | ||
| + | short_sha=" | ||
| + | repo_info=" | ||
| + | fi | ||
| + | local ref_format=" | ||
| + | repo_info=" | ||
| + | local inside_worktree=" | ||
| + | repo_info=" | ||
| + | local bare_repo=" | ||
| + | repo_info=" | ||
| + | local inside_gitdir=" | ||
| + | local g=" | ||
| + | |||
| + | if [ " | ||
| + | [ -n " | ||
| + | [ "$(git config --bool bash.hideIfPwdIgnored)" | ||
| + | git check-ignore -q . | ||
| + | then | ||
| + | return $exit | ||
| + | fi | ||
| + | |||
| + | local sparse="" | ||
| + | if [ -z " | ||
| + | [ -z " | ||
| + | [ "$(git config --bool core.sparseCheckout)" | ||
| + | sparse=" | ||
| + | fi | ||
| + | |||
| + | local r="" | ||
| + | local b="" | ||
| + | local step="" | ||
| + | local total="" | ||
| + | if [ -d " | ||
| + | __git_eread " | ||
| + | __git_eread " | ||
| + | __git_eread " | ||
| + | r=" | ||
| + | else | ||
| + | if [ -d " | ||
| + | __git_eread " | ||
| + | __git_eread " | ||
| + | if [ -f " | ||
| + | __git_eread " | ||
| + | r=" | ||
| + | elif [ -f " | ||
| + | r=" | ||
| + | else | ||
| + | r=" | ||
| + | fi | ||
| + | elif [ -f " | ||
| + | r=" | ||
| + | elif __git_sequencer_status; | ||
| + | : | ||
| + | elif [ -f " | ||
| + | r=" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | : | ||
| + | elif [ -h " | ||
| + | # symlink symbolic ref | ||
| + | b=" | ||
| + | else | ||
| + | local head="" | ||
| + | |||
| + | case " | ||
| + | files) | ||
| + | if ! __git_eread " | ||
| + | return $exit | ||
| + | fi | ||
| + | |||
| + | if [[ $head == "ref: "* ]]; then | ||
| + | head=" | ||
| + | else | ||
| + | head="" | ||
| + | fi | ||
| + | ;; | ||
| + | *) | ||
| + | head=" | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | if test -z " | ||
| + | detached=yes | ||
| + | b=" | ||
| + | case " | ||
| + | (contains) | ||
| + | git describe --contains HEAD ;; | ||
| + | (branch) | ||
| + | git describe --contains --all HEAD ;; | ||
| + | (tag) | ||
| + | git describe --tags HEAD ;; | ||
| + | (describe) | ||
| + | git describe HEAD ;; | ||
| + | (* | default) | ||
| + | git describe --tags --exact-match HEAD ;; | ||
| + | esac 2>/ | ||
| + | |||
| + | b=" | ||
| + | b=" | ||
| + | else | ||
| + | b=" | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | r=" | ||
| + | fi | ||
| + | |||
| + | local conflict="" | ||
| + | if [[ " | ||
| + | [[ $(git ls-files --unmerged 2>/ | ||
| + | conflict=" | ||
| + | fi | ||
| + | |||
| + | local w="" | ||
| + | local i="" | ||
| + | local s="" | ||
| + | local u="" | ||
| + | local h="" | ||
| + | local c="" | ||
| + | local p="" | ||
| + | local upstream="" | ||
| + | |||
| + | if [ " | ||
| + | if [ " | ||
| + | c=" | ||
| + | else | ||
| + | b=" | ||
| + | fi | ||
| + | elif [ " | ||
| + | if [ -n " | ||
| + | [ "$(git config --bool bash.showDirtyState)" | ||
| + | then | ||
| + | git diff --no-ext-diff --quiet || w=" | ||
| + | git diff --no-ext-diff --cached --quiet || i=" | ||
| + | if [ -z " | ||
| + | i="#" | ||
| + | fi | ||
| + | fi | ||
| + | if [ -n " | ||
| + | git rev-parse --verify --quiet refs/stash >/ | ||
| + | then | ||
| + | s=" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | [ "$(git config --bool bash.showUntrackedFiles)" | ||
| + | git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/ | ||
| + | then | ||
| + | u=" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | [ "$(git config --bool core.sparseCheckout)" | ||
| + | h="?" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | __git_ps1_show_upstream | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | local z=" | ||
| + | |||
| + | b=${b## | ||
| + | if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then | ||
| + | __git_ps1_branch_name=$b | ||
| + | b=" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | __git_ps1_colorize_gitstring | ||
| + | fi | ||
| + | |||
| + | local f=" | ||
| + | local gitstring=" | ||
| + | |||
| + | if [ $pcmode = yes ]; then | ||
| + | if [ " | ||
| + | gitstring=$(printf -- " | ||
| + | else | ||
| + | printf -v gitstring -- " | ||
| + | fi | ||
| + | PS1=" | ||
| + | else | ||
| + | printf -- " | ||
| + | fi | ||
| + | |||
| + | return $exit | ||
| + | } | ||
| + | </ | ||