Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 50.29 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## mate ~/.gemrc
  2.  
  3. # add this line anywhere - just as it is
  4. gem: --no-rdoc --no-ri
  5.  
  6. ## gem install wirble
  7.  
  8. ## mate ~/.irbrc
  9.  
  10. # load libraries
  11. require 'rubygems'
  12. require 'wirble'
  13.  
  14. # start wirble (with color)
  15.  
  16. Wirble.init(:skip_prompt => true, :skip_history => true)
  17. Wirble.colorize
  18.  
  19. require 'irb/completion'
  20. require 'irb/ext/save-history'
  21.  
  22. ARGV.concat [ "--readline",
  23.               "--prompt-mode",
  24.               "simple" ]
  25.  
  26.  
  27.               # 25 entries in the list
  28.               IRB.conf[:SAVE_HISTORY] = 25
  29.  
  30.               # Store results in home directory with specified file name
  31.               IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
  32.  
  33. def history(how_many = 50)
  34.   history_size = Readline::HISTORY.size
  35.  
  36.   # no lines, get out of here
  37.   puts "No history" and return if history_size == 0
  38.  
  39.   start_index = 0
  40.  
  41.   # not enough lines, only show what we have
  42.   if history_size <= how_many
  43.     how_many  = history_size - 1
  44.     end_index = how_many
  45.   else
  46.     end_index = history_size - 1 # -1 to adjust for array offset
  47.     start_index = end_index - how_many
  48.   end
  49.  
  50.   start_index.upto(end_index) {|i| print_line i}
  51.   nil
  52. end
  53. alias :h  :history
  54.  
  55. # -2 because -1 is ourself
  56. def history_do(lines = (Readline::HISTORY.size - 2))
  57.   irb_eval lines
  58.   nil
  59. end
  60. alias :h! :history_do
  61.  
  62. def history_write(filename, lines)
  63.   file = File.open(filename, 'w')
  64.  
  65.   get_lines(lines).each do |l|
  66.     file << "#{l}\n"
  67.   end
  68.  
  69.   file.close
  70. end
  71. alias :hw :history_write
  72.  
  73. private
  74. def get_line(line_number)
  75.   Readline::HISTORY[line_number]
  76. end
  77.  
  78. def get_lines(lines = [])
  79.   return [get_line(lines)] if lines.is_a? Fixnum
  80.  
  81.   out = []
  82.  
  83.   lines = lines.to_a if lines.is_a? Range
  84.  
  85.   lines.each do |l|
  86.     out << Readline::HISTORY[l]
  87.   end
  88.  
  89.   return out
  90. end
  91.  
  92. def print_line(line_number, show_line_numbers = true)
  93.  # print "[%04d] " % line_number if show_line_numbers
  94.   puts get_line(line_number)
  95. end
  96.  
  97. def irb_eval(lines)
  98.   to_eval = get_lines(lines)
  99.  
  100.   eval to_eval.join("\n")
  101.  
  102.   to_eval.each {|l| Readline::HISTORY << l}
  103. end
  104.  
  105.  
  106. script_console_running = ENV.include?('RAILS_ENV') &&
  107.                          IRB.conf[:LOAD_MODULES] &&
  108.                          IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
  109. rails_running = ENV.include?('RAILS_ENV') &&
  110.                 !(IRB.conf[:LOAD_MODULES] &&
  111.                 IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
  112. irb_standalone_running = !script_console_running && !rails_running
  113. if script_console_running
  114.   require 'logger'
  115.   Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
  116. end
  117.  
  118.  
  119.  
  120. ## mate ~/.bash_profile
  121.  
  122. source ~/.git_completion.bash
  123. PS1='\W$(__git_ps1 " Git:(%s)")\$ '
  124.  
  125. ## mate ~/.git_completion.bash
  126.  
  127. #!bash
  128. #
  129. # bash completion support for core Git.
  130. #
  131. # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  132. # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  133. # Distributed under the GNU General Public License, version 2.0.
  134. #
  135. # The contained completion routines provide support for completing:
  136. #
  137. #    *) local and remote branch names
  138. #    *) local and remote tag names
  139. #    *) .git/remotes file names
  140. #    *) git 'subcommands'
  141. #    *) tree paths within 'ref:path/to/file' expressions
  142. #    *) common --long-options
  143. #
  144. # To use these routines:
  145. #
  146. #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  147. #    2) Added the following line to your .bashrc:
  148. #        source ~/.git-completion.sh
  149. #
  150. #    3) Consider changing your PS1 to also show the current branch:
  151. #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  152. #
  153. #       The argument to __git_ps1 will be displayed only if you
  154. #       are currently in a git repository.  The %s token will be
  155. #       the name of the current branch.
  156. #
  157. #       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
  158. #       value, unstaged (*) and staged (+) changes will be shown next
  159. #       to the branch name.  You can configure this per-repository
  160. #       with the bash.showDirtyState variable, which defaults to true
  161. #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
  162. #
  163. #       You can also see if currently something is stashed, by setting
  164. #       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
  165. #       then a '$' will be shown next to the branch name.
  166. #
  167. #       If you would like to see if there're untracked files, then you can
  168. #       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
  169. #       untracked files, then a '%' will be shown next to the branch name.
  170. #
  171. # To submit patches:
  172. #
  173. #    *) Read Documentation/SubmittingPatches
  174. #    *) Send all patches to the current maintainer:
  175. #
  176. #       "Shawn O. Pearce" <spearce@spearce.org>
  177. #
  178. #    *) Always CC the Git mailing list:
  179. #
  180. #       git@vger.kernel.org
  181. #
  182.  
  183. case "$COMP_WORDBREAKS" in
  184. *:*) : great ;;
  185. *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  186. esac
  187.  
  188. # __gitdir accepts 0 or 1 arguments (i.e., location)
  189. # returns location of .git repo
  190. __gitdir ()
  191. {
  192.         if [ -z "${1-}" ]; then
  193.                 if [ -n "${__git_dir-}" ]; then
  194.                         echo "$__git_dir"
  195.                 elif [ -d .git ]; then
  196.                         echo .git
  197.                 else
  198.                         git rev-parse --git-dir 2>/dev/null
  199.                 fi
  200.         elif [ -d "$1/.git" ]; then
  201.                 echo "$1/.git"
  202.         else
  203.                 echo "$1"
  204.         fi
  205. }
  206.  
  207. # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
  208. # returns text to add to bash PS1 prompt (includes branch name)
  209. __git_ps1 ()
  210. {
  211.         local g="$(__gitdir)"
  212.         if [ -n "$g" ]; then
  213.                 local r
  214.                 local b
  215.                 if [ -f "$g/rebase-merge/interactive" ]; then
  216.                         r="|REBASE-i"
  217.                         b="$(cat "$g/rebase-merge/head-name")"
  218.                 elif [ -d "$g/rebase-merge" ]; then
  219.                         r="|REBASE-m"
  220.                         b="$(cat "$g/rebase-merge/head-name")"
  221.                 else
  222.                         if [ -d "$g/rebase-apply" ]; then
  223.                                 if [ -f "$g/rebase-apply/rebasing" ]; then
  224.                                         r="|REBASE"
  225.                                 elif [ -f "$g/rebase-apply/applying" ]; then
  226.                                         r="|AM"
  227.                                 else
  228.                                         r="|AM/REBASE"
  229.                                 fi
  230.                         elif [ -f "$g/MERGE_HEAD" ]; then
  231.                                 r="|MERGING"
  232.                         elif [ -f "$g/BISECT_LOG" ]; then
  233.                                 r="|BISECTING"
  234.                         fi
  235.  
  236.                         b="$(git symbolic-ref HEAD 2>/dev/null)" || {
  237.  
  238.                                 b="$(
  239.                                 case "${GIT_PS1_DESCRIBE_STYLE-}" in
  240.                                 (contains)
  241.                                         git describe --contains HEAD ;;
  242.                                 (branch)
  243.                                         git describe --contains --all HEAD ;;
  244.                                 (describe)
  245.                                         git describe HEAD ;;
  246.                                 (* | default)
  247.                                         git describe --exact-match HEAD ;;
  248.                                 esac 2>/dev/null)" ||
  249.  
  250.                                 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
  251.                                 b="unknown"
  252.                                 b="($b)"
  253.                         }
  254.                 fi
  255.  
  256.                 local w
  257.                 local i
  258.                 local s
  259.                 local u
  260.                 local c
  261.  
  262.                 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
  263.                         if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
  264.                                 c="BARE:"
  265.                         else
  266.                                 b="GIT_DIR!"
  267.                         fi
  268.                 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
  269.                         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
  270.                                 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
  271.                                         git diff --no-ext-diff --quiet --exit-code || w="*"
  272.                                         if git rev-parse --quiet --verify HEAD >/dev/null; then
  273.                                                 git diff-index --cached --quiet HEAD -- || i="+"
  274.                                         else
  275.                                                 i="#"
  276.                                         fi
  277.                                 fi
  278.                         fi
  279.                         if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
  280.                                 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
  281.                         fi
  282.  
  283.                         if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
  284.                            if [ -n "$(git ls-files --others --exclude-standard)" ]; then
  285.                               u="%"
  286.                            fi
  287.                         fi
  288.                 fi
  289.  
  290.                 local f="$w$i$s$u"
  291.                 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
  292.         fi
  293. }
  294.  
  295. # __gitcomp_1 requires 2 arguments
  296. __gitcomp_1 ()
  297. {
  298.         local c IFS=' '$'\t'$'\n'
  299.         for c in $1; do
  300.                 case "$c$2" in
  301.                 --*=*) printf %s$'\n' "$c$2" ;;
  302.                 *.)    printf %s$'\n' "$c$2" ;;
  303.                 *)     printf %s$'\n' "$c$2 " ;;
  304.                 esac
  305.         done
  306. }
  307.  
  308. # __gitcomp accepts 1, 2, 3, or 4 arguments
  309. # generates completion reply with compgen
  310. __gitcomp ()
  311. {
  312.         local cur="${COMP_WORDS[COMP_CWORD]}"
  313.         if [ $# -gt 2 ]; then
  314.                 cur="$3"
  315.         fi
  316.         case "$cur" in
  317.         --*=)
  318.                 COMPREPLY=()
  319.                 ;;
  320.         *)
  321.                 local IFS=$'\n'
  322.                 COMPREPLY=($(compgen -P "${2-}" \
  323.                         -W "$(__gitcomp_1 "${1-}" "${4-}")" \
  324.                         -- "$cur"))
  325.                 ;;
  326.         esac
  327. }
  328.  
  329. # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
  330. __git_heads ()
  331. {
  332.         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
  333.         if [ -d "$dir" ]; then
  334.                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  335.                         refs/heads
  336.                 return
  337.         fi
  338.         for i in $(git ls-remote "${1-}" 2>/dev/null); do
  339.                 case "$is_hash,$i" in
  340.                 y,*) is_hash=n ;;
  341.                 n,*^{}) is_hash=y ;;
  342.                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  343.                 n,*) is_hash=y; echo "$i" ;;
  344.                 esac
  345.         done
  346. }
  347.  
  348. # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
  349. __git_tags ()
  350. {
  351.         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
  352.         if [ -d "$dir" ]; then
  353.                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  354.                         refs/tags
  355.                 return
  356.         fi
  357.         for i in $(git ls-remote "${1-}" 2>/dev/null); do
  358.                 case "$is_hash,$i" in
  359.                 y,*) is_hash=n ;;
  360.                 n,*^{}) is_hash=y ;;
  361.                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  362.                 n,*) is_hash=y; echo "$i" ;;
  363.                 esac
  364.         done
  365. }
  366.  
  367. # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
  368. __git_refs ()
  369. {
  370.         local i is_hash=y dir="$(__gitdir "${1-}")"
  371.         local cur="${COMP_WORDS[COMP_CWORD]}" format refs
  372.         if [ -d "$dir" ]; then
  373.                 case "$cur" in
  374.                 refs|refs/*)
  375.                         format="refname"
  376.                         refs="${cur%/*}"
  377.                         ;;
  378.                 *)
  379.                         for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
  380.                                 if [ -e "$dir/$i" ]; then echo $i; fi
  381.                         done
  382.                         format="refname:short"
  383.                         refs="refs/tags refs/heads refs/remotes"
  384.                         ;;
  385.                 esac
  386.                 git --git-dir="$dir" for-each-ref --format="%($format)" \
  387.                         $refs
  388.                 return
  389.         fi
  390.         for i in $(git ls-remote "$dir" 2>/dev/null); do
  391.                 case "$is_hash,$i" in
  392.                 y,*) is_hash=n ;;
  393.                 n,*^{}) is_hash=y ;;
  394.                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  395.                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  396.                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
  397.                 n,*) is_hash=y; echo "$i" ;;
  398.                 esac
  399.         done
  400. }
  401.  
  402. # __git_refs2 requires 1 argument (to pass to __git_refs)
  403. __git_refs2 ()
  404. {
  405.         local i
  406.         for i in $(__git_refs "$1"); do
  407.                 echo "$i:$i"
  408.         done
  409. }
  410.  
  411. # __git_refs_remotes requires 1 argument (to pass to ls-remote)
  412. __git_refs_remotes ()
  413. {
  414.         local cmd i is_hash=y
  415.         for i in $(git ls-remote "$1" 2>/dev/null); do
  416.                 case "$is_hash,$i" in
  417.                 n,refs/heads/*)
  418.                         is_hash=y
  419.                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
  420.                         ;;
  421.                 y,*) is_hash=n ;;
  422.                 n,*^{}) is_hash=y ;;
  423.                 n,refs/tags/*) is_hash=y;;
  424.                 n,*) is_hash=y; ;;
  425.                 esac
  426.         done
  427. }
  428.  
  429. __git_remotes ()
  430. {
  431.         local i ngoff IFS=$'\n' d="$(__gitdir)"
  432.         shopt -q nullglob || ngoff=1
  433.         shopt -s nullglob
  434.         for i in "$d/remotes"/*; do
  435.                 echo ${i#$d/remotes/}
  436.         done
  437.         [ "$ngoff" ] && shopt -u nullglob
  438.         for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
  439.                 i="${i#remote.}"
  440.                 echo "${i/.url*/}"
  441.         done
  442. }
  443.  
  444. __git_list_merge_strategies ()
  445. {
  446.         git merge -s help 2>&1 |
  447.         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  448.                 s/\.$//
  449.                 s/.*://
  450.                 s/^[    ]*//
  451.                 s/[     ]*$//
  452.                 p
  453.         }'
  454. }
  455.  
  456. __git_merge_strategies=
  457. # 'git merge -s help' (and thus detection of the merge strategy
  458. # list) fails, unfortunately, if run outside of any git working
  459. # tree.  __git_merge_strategies is set to the empty string in
  460. # that case, and the detection will be repeated the next time it
  461. # is needed.
  462. __git_compute_merge_strategies ()
  463. {
  464.         : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
  465. }
  466.  
  467. __git_complete_file ()
  468. {
  469.         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
  470.         case "$cur" in
  471.         ?*:*)
  472.                 ref="${cur%%:*}"
  473.                 cur="${cur#*:}"
  474.                 case "$cur" in
  475.                 ?*/*)
  476.                         pfx="${cur%/*}"
  477.                         cur="${cur##*/}"
  478.                         ls="$ref:$pfx"
  479.                         pfx="$pfx/"
  480.                         ;;
  481.                 *)
  482.                         ls="$ref"
  483.                         ;;
  484.             esac
  485.  
  486.                 case "$COMP_WORDBREAKS" in
  487.                 *:*) : great ;;
  488.                 *)   pfx="$ref:$pfx" ;;
  489.                 esac
  490.  
  491.                 local IFS=$'\n'
  492.                 COMPREPLY=($(compgen -P "$pfx" \
  493.                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
  494.                                 | sed '/^100... blob /{
  495.                                            s,^.*        ,,
  496.                                            s,$, ,
  497.                                        }
  498.                                        /^120000 blob /{
  499.                                            s,^.*        ,,
  500.                                            s,$, ,
  501.                                        }
  502.                                        /^040000 tree /{
  503.                                            s,^.*        ,,
  504.                                            s,$,/,
  505.                                        }
  506.                                        s/^.*    //')" \
  507.                         -- "$cur"))
  508.                 ;;
  509.         *)
  510.                 __gitcomp "$(__git_refs)"
  511.                 ;;
  512.         esac
  513. }
  514.  
  515. __git_complete_revlist ()
  516. {
  517.         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
  518.         case "$cur" in
  519.         *...*)
  520.                 pfx="${cur%...*}..."
  521.                 cur="${cur#*...}"
  522.                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
  523.                 ;;
  524.         *..*)
  525.                 pfx="${cur%..*}.."
  526.                 cur="${cur#*..}"
  527.                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
  528.                 ;;
  529.         *)
  530.                 __gitcomp "$(__git_refs)"
  531.                 ;;
  532.         esac
  533. }
  534.  
  535. __git_complete_remote_or_refspec ()
  536. {
  537.         local cmd="${COMP_WORDS[1]}"
  538.         local cur="${COMP_WORDS[COMP_CWORD]}"
  539.         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  540.         while [ $c -lt $COMP_CWORD ]; do
  541.                 i="${COMP_WORDS[c]}"
  542.                 case "$i" in
  543.                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  544.                 --all)
  545.                         case "$cmd" in
  546.                         push) no_complete_refspec=1 ;;
  547.                         fetch)
  548.                                 COMPREPLY=()
  549.                                 return
  550.                                 ;;
  551.                         *) ;;
  552.                         esac
  553.                         ;;
  554.                 -*) ;;
  555.                 *) remote="$i"; break ;;
  556.                 esac
  557.                 c=$((++c))
  558.         done
  559.         if [ -z "$remote" ]; then
  560.                 __gitcomp "$(__git_remotes)"
  561.                 return
  562.         fi
  563.         if [ $no_complete_refspec = 1 ]; then
  564.                 COMPREPLY=()
  565.                 return
  566.         fi
  567.         [ "$remote" = "." ] && remote=
  568.         case "$cur" in
  569.         *:*)
  570.                 case "$COMP_WORDBREAKS" in
  571.                 *:*) : great ;;
  572.                 *)   pfx="${cur%%:*}:" ;;
  573.                 esac
  574.                 cur="${cur#*:}"
  575.                 lhs=0
  576.                 ;;
  577.         +*)
  578.                 pfx="+"
  579.                 cur="${cur#+}"
  580.                 ;;
  581.         esac
  582.         case "$cmd" in
  583.         fetch)
  584.                 if [ $lhs = 1 ]; then
  585.                         __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
  586.                 else
  587.                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
  588.                 fi
  589.                 ;;
  590.         pull)
  591.                 if [ $lhs = 1 ]; then
  592.                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
  593.                 else
  594.                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
  595.                 fi
  596.                 ;;
  597.         push)
  598.                 if [ $lhs = 1 ]; then
  599.                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
  600.                 else
  601.                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
  602.                 fi
  603.                 ;;
  604.         esac
  605. }
  606.  
  607. __git_complete_strategy ()
  608. {
  609.         __git_compute_merge_strategies
  610.         case "${COMP_WORDS[COMP_CWORD-1]}" in
  611.         -s|--strategy)
  612.                 __gitcomp "$__git_merge_strategies"
  613.                 return 0
  614.         esac
  615.         local cur="${COMP_WORDS[COMP_CWORD]}"
  616.         case "$cur" in
  617.         --strategy=*)
  618.                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  619.                 return 0
  620.                 ;;
  621.         esac
  622.         return 1
  623. }
  624.  
  625. __git_list_all_commands ()
  626. {
  627.         local i IFS=" "$'\n'
  628.         for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
  629.         do
  630.                 case $i in
  631.                 *--*)             : helper pattern;;
  632.                 *) echo $i;;
  633.                 esac
  634.         done
  635. }
  636.  
  637. __git_all_commands=
  638. __git_compute_all_commands ()
  639. {
  640.         : ${__git_all_commands:=$(__git_list_all_commands)}
  641. }
  642.  
  643. __git_list_porcelain_commands ()
  644. {
  645.         local i IFS=" "$'\n'
  646.         __git_compute_all_commands
  647.         for i in "help" $__git_all_commands
  648.         do
  649.                 case $i in
  650.                 *--*)             : helper pattern;;
  651.                 applymbox)        : ask gittus;;
  652.                 applypatch)       : ask gittus;;
  653.                 archimport)       : import;;
  654.                 cat-file)         : plumbing;;
  655.                 check-attr)       : plumbing;;
  656.                 check-ref-format) : plumbing;;
  657.                 checkout-index)   : plumbing;;
  658.                 commit-tree)      : plumbing;;
  659.                 count-objects)    : infrequent;;
  660.                 cvsexportcommit)  : export;;
  661.                 cvsimport)        : import;;
  662.                 cvsserver)        : daemon;;
  663.                 daemon)           : daemon;;
  664.                 diff-files)       : plumbing;;
  665.                 diff-index)       : plumbing;;
  666.                 diff-tree)        : plumbing;;
  667.                 fast-import)      : import;;
  668.                 fast-export)      : export;;
  669.                 fsck-objects)     : plumbing;;
  670.                 fetch-pack)       : plumbing;;
  671.                 fmt-merge-msg)    : plumbing;;
  672.                 for-each-ref)     : plumbing;;
  673.                 hash-object)      : plumbing;;
  674.                 http-*)           : transport;;
  675.                 index-pack)       : plumbing;;
  676.                 init-db)          : deprecated;;
  677.                 local-fetch)      : plumbing;;
  678.                 lost-found)       : infrequent;;
  679.                 ls-files)         : plumbing;;
  680.                 ls-remote)        : plumbing;;
  681.                 ls-tree)          : plumbing;;
  682.                 mailinfo)         : plumbing;;
  683.                 mailsplit)        : plumbing;;
  684.                 merge-*)          : plumbing;;
  685.                 mktree)           : plumbing;;
  686.                 mktag)            : plumbing;;
  687.                 pack-objects)     : plumbing;;
  688.                 pack-redundant)   : plumbing;;
  689.                 pack-refs)        : plumbing;;
  690.                 parse-remote)     : plumbing;;
  691.                 patch-id)         : plumbing;;
  692.                 peek-remote)      : plumbing;;
  693.                 prune)            : plumbing;;
  694.                 prune-packed)     : plumbing;;
  695.                 quiltimport)      : import;;
  696.                 read-tree)        : plumbing;;
  697.                 receive-pack)     : plumbing;;
  698.                 reflog)           : plumbing;;
  699.                 remote-*)         : transport;;
  700.                 repo-config)      : deprecated;;
  701.                 rerere)           : plumbing;;
  702.                 rev-list)         : plumbing;;
  703.                 rev-parse)        : plumbing;;
  704.                 runstatus)        : plumbing;;
  705.                 sh-setup)         : internal;;
  706.                 shell)            : daemon;;
  707.                 show-ref)         : plumbing;;
  708.                 send-pack)        : plumbing;;
  709.                 show-index)       : plumbing;;
  710.                 ssh-*)            : transport;;
  711.                 stripspace)       : plumbing;;
  712.                 symbolic-ref)     : plumbing;;
  713.                 tar-tree)         : deprecated;;
  714.                 unpack-file)      : plumbing;;
  715.                 unpack-objects)   : plumbing;;
  716.                 update-index)     : plumbing;;
  717.                 update-ref)       : plumbing;;
  718.                 update-server-info) : daemon;;
  719.                 upload-archive)   : plumbing;;
  720.                 upload-pack)      : plumbing;;
  721.                 write-tree)       : plumbing;;
  722.                 var)              : infrequent;;
  723.                 verify-pack)      : infrequent;;
  724.                 verify-tag)       : plumbing;;
  725.                 *) echo $i;;
  726.                 esac
  727.         done
  728. }
  729.  
  730. __git_porcelain_commands=
  731. __git_compute_porcelain_commands ()
  732. {
  733.         __git_compute_all_commands
  734.         : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
  735. }
  736.  
  737. __git_aliases ()
  738. {
  739.         local i IFS=$'\n'
  740.         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
  741.                 case "$i" in
  742.                 alias.*)
  743.                         i="${i#alias.}"
  744.                         echo "${i/ */}"
  745.                         ;;
  746.                 esac
  747.         done
  748. }
  749.  
  750. # __git_aliased_command requires 1 argument
  751. __git_aliased_command ()
  752. {
  753.         local word cmdline=$(git --git-dir="$(__gitdir)" \
  754.                 config --get "alias.$1")
  755.         for word in $cmdline; do
  756.                 if [ "${word##-*}" ]; then
  757.                         echo $word
  758.                         return
  759.                 fi
  760.         done
  761. }
  762.  
  763. # __git_find_on_cmdline requires 1 argument
  764. __git_find_on_cmdline ()
  765. {
  766.         local word subcommand c=1
  767.  
  768.         while [ $c -lt $COMP_CWORD ]; do
  769.                 word="${COMP_WORDS[c]}"
  770.                 for subcommand in $1; do
  771.                         if [ "$subcommand" = "$word" ]; then
  772.                                 echo "$subcommand"
  773.                                 return
  774.                         fi
  775.                 done
  776.                 c=$((++c))
  777.         done
  778. }
  779.  
  780. __git_has_doubledash ()
  781. {
  782.         local c=1
  783.         while [ $c -lt $COMP_CWORD ]; do
  784.                 if [ "--" = "${COMP_WORDS[c]}" ]; then
  785.                         return 0
  786.                 fi
  787.                 c=$((++c))
  788.         done
  789.         return 1
  790. }
  791.  
  792. __git_whitespacelist="nowarn warn error error-all fix"
  793.  
  794. _git_am ()
  795. {
  796.         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
  797.         if [ -d "$dir"/rebase-apply ]; then
  798.                 __gitcomp "--skip --continue --resolved --abort"
  799.                 return
  800.         fi
  801.         case "$cur" in
  802.         --whitespace=*)
  803.                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  804.                 return
  805.                 ;;
  806.         --*)
  807.                 __gitcomp "
  808.                         --3way --committer-date-is-author-date --ignore-date
  809.                         --ignore-whitespace --ignore-space-change
  810.                         --interactive --keep --no-utf8 --signoff --utf8
  811.                         --whitespace= --scissors
  812.                         "
  813.                 return
  814.         esac
  815.         COMPREPLY=()
  816. }
  817.  
  818. _git_apply ()
  819. {
  820.         local cur="${COMP_WORDS[COMP_CWORD]}"
  821.         case "$cur" in
  822.         --whitespace=*)
  823.                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  824.                 return
  825.                 ;;
  826.         --*)
  827.                 __gitcomp "
  828.                         --stat --numstat --summary --check --index
  829.                         --cached --index-info --reverse --reject --unidiff-zero
  830.                         --apply --no-add --exclude=
  831.                         --ignore-whitespace --ignore-space-change
  832.                         --whitespace= --inaccurate-eof --verbose
  833.                         "
  834.                 return
  835.         esac
  836.         COMPREPLY=()
  837. }
  838.  
  839. _git_add ()
  840. {
  841.         __git_has_doubledash && return
  842.  
  843.         local cur="${COMP_WORDS[COMP_CWORD]}"
  844.         case "$cur" in
  845.         --*)
  846.                 __gitcomp "
  847.                         --interactive --refresh --patch --update --dry-run
  848.                         --ignore-errors --intent-to-add
  849.                         "
  850.                 return
  851.         esac
  852.         COMPREPLY=()
  853. }
  854.  
  855. _git_archive ()
  856. {
  857.         local cur="${COMP_WORDS[COMP_CWORD]}"
  858.         case "$cur" in
  859.         --format=*)
  860.                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
  861.                 return
  862.                 ;;
  863.         --remote=*)
  864.                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
  865.                 return
  866.                 ;;
  867.         --*)
  868.                 __gitcomp "
  869.                         --format= --list --verbose
  870.                         --prefix= --remote= --exec=
  871.                         "
  872.                 return
  873.                 ;;
  874.         esac
  875.         __git_complete_file
  876. }
  877.  
  878. _git_bisect ()
  879. {
  880.         __git_has_doubledash && return
  881.  
  882.         local subcommands="start bad good skip reset visualize replay log run"
  883.         local subcommand="$(__git_find_on_cmdline "$subcommands")"
  884.         if [ -z "$subcommand" ]; then
  885.                 __gitcomp "$subcommands"
  886.                 return
  887.         fi
  888.  
  889.         case "$subcommand" in
  890.         bad|good|reset|skip)
  891.                 __gitcomp "$(__git_refs)"
  892.                 ;;
  893.         *)
  894.                 COMPREPLY=()
  895.                 ;;
  896.         esac
  897. }
  898.  
  899. _git_branch ()
  900. {
  901.         local i c=1 only_local_ref="n" has_r="n"
  902.  
  903.         while [ $c -lt $COMP_CWORD ]; do
  904.                 i="${COMP_WORDS[c]}"
  905.                 case "$i" in
  906.                 -d|-m)  only_local_ref="y" ;;
  907.                 -r)     has_r="y" ;;
  908.                 esac
  909.                 c=$((++c))
  910.         done
  911.  
  912.         case "${COMP_WORDS[COMP_CWORD]}" in
  913.         --*)
  914.                 __gitcomp "
  915.                         --color --no-color --verbose --abbrev= --no-abbrev
  916.                         --track --no-track --contains --merged --no-merged
  917.                         "
  918.                 ;;
  919.         *)
  920.                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  921.                         __gitcomp "$(__git_heads)"
  922.                 else
  923.                         __gitcomp "$(__git_refs)"
  924.                 fi
  925.                 ;;
  926.         esac
  927. }
  928.  
  929. _git_bundle ()
  930. {
  931.         local cmd="${COMP_WORDS[2]}"
  932.         case "$COMP_CWORD" in
  933.         2)
  934.                 __gitcomp "create list-heads verify unbundle"
  935.                 ;;
  936.         3)
  937.                 # looking for a file
  938.                 ;;
  939.         *)
  940.                 case "$cmd" in
  941.                         create)
  942.                                 __git_complete_revlist
  943.                         ;;
  944.                 esac
  945.                 ;;
  946.         esac
  947. }
  948.  
  949. _git_checkout ()
  950. {
  951.         __git_has_doubledash && return
  952.  
  953.         local cur="${COMP_WORDS[COMP_CWORD]}"
  954.         case "$cur" in
  955.         --conflict=*)
  956.                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
  957.                 ;;
  958.         --*)
  959.                 __gitcomp "
  960.                         --quiet --ours --theirs --track --no-track --merge
  961.                         --conflict= --patch
  962.                         "
  963.                 ;;
  964.         *)
  965.                 __gitcomp "$(__git_refs)"
  966.                 ;;
  967.         esac
  968. }
  969.  
  970. _git_cherry ()
  971. {
  972.         __gitcomp "$(__git_refs)"
  973. }
  974.  
  975. _git_cherry_pick ()
  976. {
  977.         local cur="${COMP_WORDS[COMP_CWORD]}"
  978.         case "$cur" in
  979.         --*)
  980.                 __gitcomp "--edit --no-commit"
  981.                 ;;
  982.         *)
  983.                 __gitcomp "$(__git_refs)"
  984.                 ;;
  985.         esac
  986. }
  987.  
  988. _git_clean ()
  989. {
  990.         __git_has_doubledash && return
  991.  
  992.         local cur="${COMP_WORDS[COMP_CWORD]}"
  993.         case "$cur" in
  994.         --*)
  995.                 __gitcomp "--dry-run --quiet"
  996.                 return
  997.                 ;;
  998.         esac
  999.         COMPREPLY=()
  1000. }
  1001.  
  1002. _git_clone ()
  1003. {
  1004.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1005.         case "$cur" in
  1006.         --*)
  1007.                 __gitcomp "
  1008.                         --local
  1009.                         --no-hardlinks
  1010.                         --shared
  1011.                         --reference
  1012.                         --quiet
  1013.                         --no-checkout
  1014.                         --bare
  1015.                         --mirror
  1016.                         --origin
  1017.                         --upload-pack
  1018.                         --template=
  1019.                         --depth
  1020.                         "
  1021.                 return
  1022.                 ;;
  1023.         esac
  1024.         COMPREPLY=()
  1025. }
  1026.  
  1027. _git_commit ()
  1028. {
  1029.         __git_has_doubledash && return
  1030.  
  1031.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1032.         case "$cur" in
  1033.         --cleanup=*)
  1034.                 __gitcomp "default strip verbatim whitespace
  1035.                         " "" "${cur##--cleanup=}"
  1036.                 return
  1037.                 ;;
  1038.         --reuse-message=*)
  1039.                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
  1040.                 return
  1041.                 ;;
  1042.         --reedit-message=*)
  1043.                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
  1044.                 return
  1045.                 ;;
  1046.         --untracked-files=*)
  1047.                 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
  1048.                 return
  1049.                 ;;
  1050.         --*)
  1051.                 __gitcomp "
  1052.                         --all --author= --signoff --verify --no-verify
  1053.                         --edit --amend --include --only --interactive
  1054.                         --dry-run --reuse-message= --reedit-message=
  1055.                         --reset-author --file= --message= --template=
  1056.                         --cleanup= --untracked-files --untracked-files=
  1057.                         --verbose --quiet
  1058.                         "
  1059.                 return
  1060.         esac
  1061.         COMPREPLY=()
  1062. }
  1063.  
  1064. _git_describe ()
  1065. {
  1066.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1067.         case "$cur" in
  1068.         --*)
  1069.                 __gitcomp "
  1070.                         --all --tags --contains --abbrev= --candidates=
  1071.                         --exact-match --debug --long --match --always
  1072.                         "
  1073.                 return
  1074.         esac
  1075.         __gitcomp "$(__git_refs)"
  1076. }
  1077.  
  1078. __git_diff_common_options="--stat --numstat --shortstat --summary
  1079.                         --patch-with-stat --name-only --name-status --color
  1080.                         --no-color --color-words --no-renames --check
  1081.                         --full-index --binary --abbrev --diff-filter=
  1082.                         --find-copies-harder
  1083.                         --text --ignore-space-at-eol --ignore-space-change
  1084.                         --ignore-all-space --exit-code --quiet --ext-diff
  1085.                         --no-ext-diff
  1086.                         --no-prefix --src-prefix= --dst-prefix=
  1087.                         --inter-hunk-context=
  1088.                         --patience
  1089.                         --raw
  1090.                         --dirstat --dirstat= --dirstat-by-file
  1091.                         --dirstat-by-file= --cumulative
  1092. "
  1093.  
  1094. _git_diff ()
  1095. {
  1096.         __git_has_doubledash && return
  1097.  
  1098.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1099.         case "$cur" in
  1100.         --*)
  1101.                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1102.                         --base --ours --theirs
  1103.                         $__git_diff_common_options
  1104.                         "
  1105.                 return
  1106.                 ;;
  1107.         esac
  1108.         __git_complete_file
  1109. }
  1110.  
  1111. __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
  1112.                         tkdiff vimdiff gvimdiff xxdiff araxis p4merge
  1113. "
  1114.  
  1115. _git_difftool ()
  1116. {
  1117.         __git_has_doubledash && return
  1118.  
  1119.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1120.         case "$cur" in
  1121.         --tool=*)
  1122.                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
  1123.                 return
  1124.                 ;;
  1125.         --*)
  1126.                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1127.                         --base --ours --theirs
  1128.                         --no-renames --diff-filter= --find-copies-harder
  1129.                         --relative --ignore-submodules
  1130.                         --tool="
  1131.                 return
  1132.                 ;;
  1133.         esac
  1134.         __git_complete_file
  1135. }
  1136.  
  1137. __git_fetch_options="
  1138.         --quiet --verbose --append --upload-pack --force --keep --depth=
  1139.         --tags --no-tags --all --prune --dry-run
  1140. "
  1141.  
  1142. _git_fetch ()
  1143. {
  1144.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1145.         case "$cur" in
  1146.         --*)
  1147.                 __gitcomp "$__git_fetch_options"
  1148.                 return
  1149.                 ;;
  1150.         esac
  1151.         __git_complete_remote_or_refspec
  1152. }
  1153.  
  1154. _git_format_patch ()
  1155. {
  1156.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1157.         case "$cur" in
  1158.         --thread=*)
  1159.                 __gitcomp "
  1160.                         deep shallow
  1161.                         " "" "${cur##--thread=}"
  1162.                 return
  1163.                 ;;
  1164.         --*)
  1165.                 __gitcomp "
  1166.                         --stdout --attach --no-attach --thread --thread=
  1167.                         --output-directory
  1168.                         --numbered --start-number
  1169.                         --numbered-files
  1170.                         --keep-subject
  1171.                         --signoff
  1172.                         --in-reply-to= --cc=
  1173.                         --full-index --binary
  1174.                         --not --all
  1175.                         --cover-letter
  1176.                         --no-prefix --src-prefix= --dst-prefix=
  1177.                         --inline --suffix= --ignore-if-in-upstream
  1178.                         --subject-prefix=
  1179.                         "
  1180.                 return
  1181.                 ;;
  1182.         esac
  1183.         __git_complete_revlist
  1184. }
  1185.  
  1186. _git_fsck ()
  1187. {
  1188.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1189.         case "$cur" in
  1190.         --*)
  1191.                 __gitcomp "
  1192.                         --tags --root --unreachable --cache --no-reflogs --full
  1193.                         --strict --verbose --lost-found
  1194.                         "
  1195.                 return
  1196.                 ;;
  1197.         esac
  1198.         COMPREPLY=()
  1199. }
  1200.  
  1201. _git_gc ()
  1202. {
  1203.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1204.         case "$cur" in
  1205.         --*)
  1206.                 __gitcomp "--prune --aggressive"
  1207.                 return
  1208.                 ;;
  1209.         esac
  1210.         COMPREPLY=()
  1211. }
  1212.  
  1213. _git_grep ()
  1214. {
  1215.         __git_has_doubledash && return
  1216.  
  1217.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1218.         case "$cur" in
  1219.         --*)
  1220.                 __gitcomp "
  1221.                         --cached
  1222.                         --text --ignore-case --word-regexp --invert-match
  1223.                         --full-name
  1224.                         --extended-regexp --basic-regexp --fixed-strings
  1225.                         --files-with-matches --name-only
  1226.                         --files-without-match
  1227.                         --max-depth
  1228.                         --count
  1229.                         --and --or --not --all-match
  1230.                         "
  1231.                 return
  1232.                 ;;
  1233.         esac
  1234.  
  1235.         __gitcomp "$(__git_refs)"
  1236. }
  1237.  
  1238. _git_help ()
  1239. {
  1240.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1241.         case "$cur" in
  1242.         --*)
  1243.                 __gitcomp "--all --info --man --web"
  1244.                 return
  1245.                 ;;
  1246.         esac
  1247.         __git_compute_all_commands
  1248.         __gitcomp "$__git_all_commands
  1249.                 attributes cli core-tutorial cvs-migration
  1250.                 diffcore gitk glossary hooks ignore modules
  1251.                 repository-layout tutorial tutorial-2
  1252.                 workflows
  1253.                 "
  1254. }
  1255.  
  1256. _git_init ()
  1257. {
  1258.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1259.         case "$cur" in
  1260.         --shared=*)
  1261.                 __gitcomp "
  1262.                         false true umask group all world everybody
  1263.                         " "" "${cur##--shared=}"
  1264.                 return
  1265.                 ;;
  1266.         --*)
  1267.                 __gitcomp "--quiet --bare --template= --shared --shared="
  1268.                 return
  1269.                 ;;
  1270.         esac
  1271.         COMPREPLY=()
  1272. }
  1273.  
  1274. _git_ls_files ()
  1275. {
  1276.         __git_has_doubledash && return
  1277.  
  1278.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1279.         case "$cur" in
  1280.         --*)
  1281.                 __gitcomp "--cached --deleted --modified --others --ignored
  1282.                         --stage --directory --no-empty-directory --unmerged
  1283.                         --killed --exclude= --exclude-from=
  1284.                         --exclude-per-directory= --exclude-standard
  1285.                         --error-unmatch --with-tree= --full-name
  1286.                         --abbrev --ignored --exclude-per-directory
  1287.                         "
  1288.                 return
  1289.                 ;;
  1290.         esac
  1291.         COMPREPLY=()
  1292. }
  1293.  
  1294. _git_ls_remote ()
  1295. {
  1296.         __gitcomp "$(__git_remotes)"
  1297. }
  1298.  
  1299. _git_ls_tree ()
  1300. {
  1301.         __git_complete_file
  1302. }
  1303.  
  1304. # Options that go well for log, shortlog and gitk
  1305. __git_log_common_options="
  1306.         --not --all
  1307.         --branches --tags --remotes
  1308.         --first-parent --merges --no-merges
  1309.         --max-count=
  1310.         --max-age= --since= --after=
  1311.         --min-age= --until= --before=
  1312. "
  1313. # Options that go well for log and gitk (not shortlog)
  1314. __git_log_gitk_options="
  1315.         --dense --sparse --full-history
  1316.         --simplify-merges --simplify-by-decoration
  1317.         --left-right
  1318. "
  1319. # Options that go well for log and shortlog (not gitk)
  1320. __git_log_shortlog_options="
  1321.         --author= --committer= --grep=
  1322.         --all-match
  1323. "
  1324.  
  1325. __git_log_pretty_formats="oneline short medium full fuller email raw format:"
  1326. __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
  1327.  
  1328. _git_log ()
  1329. {
  1330.         __git_has_doubledash && return
  1331.  
  1332.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1333.         local g="$(git rev-parse --git-dir 2>/dev/null)"
  1334.         local merge=""
  1335.         if [ -f "$g/MERGE_HEAD" ]; then
  1336.                 merge="--merge"
  1337.         fi
  1338.         case "$cur" in
  1339.         --pretty=*)
  1340.                 __gitcomp "$__git_log_pretty_formats
  1341.                         " "" "${cur##--pretty=}"
  1342.                 return
  1343.                 ;;
  1344.         --format=*)
  1345.                 __gitcomp "$__git_log_pretty_formats
  1346.                         " "" "${cur##--format=}"
  1347.                 return
  1348.                 ;;
  1349.         --date=*)
  1350.                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
  1351.                 return
  1352.                 ;;
  1353.         --decorate=*)
  1354.                 __gitcomp "long short" "" "${cur##--decorate=}"
  1355.                 return
  1356.                 ;;
  1357.         --*)
  1358.                 __gitcomp "
  1359.                         $__git_log_common_options
  1360.                         $__git_log_shortlog_options
  1361.                         $__git_log_gitk_options
  1362.                         --root --topo-order --date-order --reverse
  1363.                         --follow --full-diff
  1364.                         --abbrev-commit --abbrev=
  1365.                         --relative-date --date=
  1366.                         --pretty= --format= --oneline
  1367.                         --cherry-pick
  1368.                         --graph
  1369.                         --decorate --decorate=
  1370.                         --walk-reflogs
  1371.                         --parents --children
  1372.                         $merge
  1373.                         $__git_diff_common_options
  1374.                         --pickaxe-all --pickaxe-regex
  1375.                         "
  1376.                 return
  1377.                 ;;
  1378.         esac
  1379.         __git_complete_revlist
  1380. }
  1381.  
  1382. __git_merge_options="
  1383.         --no-commit --no-stat --log --no-log --squash --strategy
  1384.         --commit --stat --no-squash --ff --no-ff --ff-only
  1385. "
  1386.  
  1387. _git_merge ()
  1388. {
  1389.         __git_complete_strategy && return
  1390.  
  1391.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1392.         case "$cur" in
  1393.         --*)
  1394.                 __gitcomp "$__git_merge_options"
  1395.                 return
  1396.         esac
  1397.         __gitcomp "$(__git_refs)"
  1398. }
  1399.  
  1400. _git_mergetool ()
  1401. {
  1402.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1403.         case "$cur" in
  1404.         --tool=*)
  1405.                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
  1406.                 return
  1407.                 ;;
  1408.         --*)
  1409.                 __gitcomp "--tool="
  1410.                 return
  1411.                 ;;
  1412.         esac
  1413.         COMPREPLY=()
  1414. }
  1415.  
  1416. _git_merge_base ()
  1417. {
  1418.         __gitcomp "$(__git_refs)"
  1419. }
  1420.  
  1421. _git_mv ()
  1422. {
  1423.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1424.         case "$cur" in
  1425.         --*)
  1426.                 __gitcomp "--dry-run"
  1427.                 return
  1428.                 ;;
  1429.         esac
  1430.         COMPREPLY=()
  1431. }
  1432.  
  1433. _git_name_rev ()
  1434. {
  1435.         __gitcomp "--tags --all --stdin"
  1436. }
  1437.  
  1438. _git_notes ()
  1439. {
  1440.         local subcommands="edit show"
  1441.         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
  1442.                 __gitcomp "$subcommands"
  1443.                 return
  1444.         fi
  1445.  
  1446.         case "${COMP_WORDS[COMP_CWORD-1]}" in
  1447.         -m|-F)
  1448.                 COMPREPLY=()
  1449.                 ;;
  1450.         *)
  1451.                 __gitcomp "$(__git_refs)"
  1452.                 ;;
  1453.         esac
  1454. }
  1455.  
  1456. _git_pull ()
  1457. {
  1458.         __git_complete_strategy && return
  1459.  
  1460.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1461.         case "$cur" in
  1462.         --*)
  1463.                 __gitcomp "
  1464.                         --rebase --no-rebase
  1465.                         $__git_merge_options
  1466.                         $__git_fetch_options
  1467.                 "
  1468.                 return
  1469.                 ;;
  1470.         esac
  1471.         __git_complete_remote_or_refspec
  1472. }
  1473.  
  1474. _git_push ()
  1475. {
  1476.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1477.         case "${COMP_WORDS[COMP_CWORD-1]}" in
  1478.         --repo)
  1479.                 __gitcomp "$(__git_remotes)"
  1480.                 return
  1481.         esac
  1482.         case "$cur" in
  1483.         --repo=*)
  1484.                 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
  1485.                 return
  1486.                 ;;
  1487.         --*)
  1488.                 __gitcomp "
  1489.                         --all --mirror --tags --dry-run --force --verbose
  1490.                         --receive-pack= --repo=
  1491.                 "
  1492.                 return
  1493.                 ;;
  1494.         esac
  1495.         __git_complete_remote_or_refspec
  1496. }
  1497.  
  1498. _git_rebase ()
  1499. {
  1500.         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
  1501.         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
  1502.                 __gitcomp "--continue --skip --abort"
  1503.                 return
  1504.         fi
  1505.         __git_complete_strategy && return
  1506.         case "$cur" in
  1507.         --whitespace=*)
  1508.                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  1509.                 return
  1510.                 ;;
  1511.         --*)
  1512.                 __gitcomp "
  1513.                         --onto --merge --strategy --interactive
  1514.                         --preserve-merges --stat --no-stat
  1515.                         --committer-date-is-author-date --ignore-date
  1516.                         --ignore-whitespace --whitespace=
  1517.                         --autosquash
  1518.                         "
  1519.  
  1520.                 return
  1521.         esac
  1522.         __gitcomp "$(__git_refs)"
  1523. }
  1524.  
  1525. __git_send_email_confirm_options="always never auto cc compose"
  1526. __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
  1527.  
  1528. _git_send_email ()
  1529. {
  1530.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1531.         case "$cur" in
  1532.         --confirm=*)
  1533.                 __gitcomp "
  1534.                         $__git_send_email_confirm_options
  1535.                         " "" "${cur##--confirm=}"
  1536.                 return
  1537.                 ;;
  1538.         --suppress-cc=*)
  1539.                 __gitcomp "
  1540.                         $__git_send_email_suppresscc_options
  1541.                         " "" "${cur##--suppress-cc=}"
  1542.  
  1543.                 return
  1544.                 ;;
  1545.         --smtp-encryption=*)
  1546.                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
  1547.                 return
  1548.                 ;;
  1549.         --*)
  1550.                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
  1551.                         --compose --confirm= --dry-run --envelope-sender
  1552.                         --from --identity
  1553.                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
  1554.                         --no-suppress-from --no-thread --quiet
  1555.                         --signed-off-by-cc --smtp-pass --smtp-server
  1556.                         --smtp-server-port --smtp-encryption= --smtp-user
  1557.                         --subject --suppress-cc= --suppress-from --thread --to
  1558.                         --validate --no-validate"
  1559.                 return
  1560.                 ;;
  1561.         esac
  1562.         COMPREPLY=()
  1563. }
  1564.  
  1565. __git_config_get_set_variables ()
  1566. {
  1567.         local prevword word config_file= c=$COMP_CWORD
  1568.         while [ $c -gt 1 ]; do
  1569.                 word="${COMP_WORDS[c]}"
  1570.                 case "$word" in
  1571.                 --global|--system|--file=*)
  1572.                         config_file="$word"
  1573.                         break
  1574.                         ;;
  1575.                 -f|--file)
  1576.                         config_file="$word $prevword"
  1577.                         break
  1578.                         ;;
  1579.                 esac
  1580.                 prevword=$word
  1581.                 c=$((--c))
  1582.         done
  1583.  
  1584.         git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
  1585.         while read line
  1586.         do
  1587.                 case "$line" in
  1588.                 *.*=*)
  1589.                         echo "${line/=*/}"
  1590.                         ;;
  1591.                 esac
  1592.         done
  1593. }
  1594.  
  1595. _git_config ()
  1596. {
  1597.         local cur="${COMP_WORDS[COMP_CWORD]}"
  1598.         local prv="${COMP_WORDS[COMP_CWORD-1]}"
  1599.         case "$prv" in
  1600.         branch.*.remote)
  1601.                 __gitcomp "$(__git_remotes)"
  1602.                 return
  1603.                 ;;
  1604.         branch.*.merge)
  1605.                 __gitcomp "$(__git_refs)"
  1606.                 return
  1607.                 ;;
  1608.         remote.*.fetch)
  1609.                 local remote="${prv#remote.}"
  1610.                 remote="${remote%.fetch}"
  1611.                 __gitcomp "$(__git_refs_remotes "$remote")"
  1612.                 return
  1613.                 ;;
  1614.         remote.*.push)
  1615.                 local remote="${prv#remote.}"
  1616.                 remote="${remote%.push}"
  1617.                 __gitcomp "$(git --git-dir="$(__gitdir)" \
  1618.                         for-each-ref --format='%(refname):%(refname)' \
  1619.                         refs/heads)"
  1620.                 return
  1621.                 ;;
  1622.         pull.twohead|pull.octopus)
  1623.                 __git_compute_merge_strategies
  1624.                 __gitcomp "$__git_merge_strategies"
  1625.                 return
  1626.                 ;;
  1627.         color.branch|color.diff|color.interactive|\
  1628.         color.showbranch|color.status|color.ui)
  1629.                 __gitcomp "always never auto"
  1630.                 return
  1631.                 ;;
  1632.         color.pager)
  1633.                 __gitcomp "false true"
  1634.                 return
  1635.                 ;;
  1636.         color.*.*)
  1637.                 __gitcomp "
  1638.                         normal black red green yellow blue magenta cyan white
  1639.                         bold dim ul blink reverse
  1640.                         "
  1641.                 return
  1642.                 ;;
  1643.         help.format)
  1644.                 __gitcomp "man info web html"
  1645.                 return
  1646.                 ;;
  1647.         log.date)
  1648.                 __gitcomp "$__git_log_date_formats"
  1649.                 return
  1650.                 ;;
  1651.         sendemail.aliasesfiletype)
  1652.                 __gitcomp "mutt mailrc pine elm gnus"
  1653.                 return
  1654.                 ;;
  1655.         sendemail.confirm)
  1656.                 __gitcomp "$__git_send_email_confirm_options"
  1657.                 return
  1658.                 ;;
  1659.         sendemail.suppresscc)
  1660.                 __gitcomp "$__git_send_email_suppresscc_options"
  1661.                 return
  1662.                 ;;
  1663.         --get|--get-all|--unset|--unset-all)
  1664.                 __gitcomp "$(__git_config_get_set_variables)"
  1665.                 return
  1666.                 ;;
  1667.         *.*)
  1668.                 COMPREPLY=()
  1669.                 return
  1670.                 ;;
  1671.         esac
  1672.         case "$cur" in
  1673.         --*)
  1674.                 __gitcomp "
  1675.                         --global --system --file=
  1676.                         --list --replace-all
  1677.                         --get --get-all --get-regexp
  1678.                         --add --unset --unset-all
  1679.                         --remove-section --rename-section
  1680.                         "
  1681.                 return
  1682.                 ;;
  1683.         branch.*.*)
  1684.                 local pfx="${cur%.*}."
  1685.                 cur="${cur##*.}"
  1686.                 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
  1687.                 return
  1688.                 ;;
  1689.         branch.*)
  1690.                 local pfx="${cur%.*}."
  1691.                 cur="${cur#*.}"
  1692.                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
  1693.                 return
  1694.                 ;;
  1695.         guitool.*.*)
  1696.                 local pfx="${cur%.*}."
  1697.                 cur="${cur##*.}"
  1698.                 __gitcomp "
  1699.                         argprompt cmd confirm needsfile noconsole norescan
  1700.                         prompt revprompt revunmerged title
  1701.                         " "$pfx" "$cur"
  1702.                 return
  1703.                 ;;
  1704.         difftool.*.*)
  1705.                 local pfx="${cur%.*}."
  1706.                 cur="${cur##*.}"
  1707.                 __gitcomp "cmd path" "$pfx" "$cur"
  1708.                 return
  1709.                 ;;
  1710.         man.*.*)
  1711.                 local pfx="${cur%.*}."
  1712.                 cur="${cur##*.}"
  1713.                 __gitcomp "cmd path" "$pfx" "$cur"
  1714.                 return
  1715.                 ;;
  1716.         mergetool.*.*)
  1717.                 local pfx="${cur%.*}."
  1718.                 cur="${cur##*.}"
  1719.                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
  1720.                 return
  1721.                 ;;
  1722.         pager.*)
  1723.                 local pfx="${cur%.*}."
  1724.                 cur="${cur#*.}"
  1725.                 __git_compute_all_commands
  1726.                 __gitcomp "$__git_all_commands" "$pfx" "$cur"
  1727.                 return
  1728.                 ;;
  1729.         remote.*.*)
  1730.                 local pfx="${cur%.*}."
  1731.                 cur="${cur##*.}"
  1732.                 __gitcomp "
  1733.                         url proxy fetch push mirror skipDefaultUpdate
  1734.                         receivepack uploadpack tagopt pushurl
  1735.                         " "$pfx" "$cur"
  1736.                 return
  1737.                 ;;
  1738.         remote.*)
  1739.                 local pfx="${cur%.*}."
  1740.                 cur="${cur#*.}"
  1741.                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
  1742.                 return
  1743.                 ;;
  1744.         url.*.*)
  1745.                 local pfx="${cur%.*}."
  1746.                 cur="${cur##*.}"
  1747.                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
  1748.                 return
  1749.                 ;;
  1750.         esac
  1751.         __gitcomp "
  1752.                 add.ignore-errors
  1753.                 alias.
  1754.                 apply.ignorewhitespace
  1755.                 apply.whitespace
  1756.                 branch.autosetupmerge
  1757.                 branch.autosetuprebase
  1758.                 clean.requireForce
  1759.                 color.branch
  1760.                 color.branch.current
  1761.                 color.branch.local
  1762.                 color.branch.plain
  1763.                 color.branch.remote
  1764.                 color.diff
  1765.                 color.diff.commit
  1766.                 color.diff.frag
  1767.                 color.diff.meta
  1768.                 color.diff.new
  1769.                 color.diff.old
  1770.                 color.diff.plain
  1771.                 color.diff.whitespace
  1772.                 color.grep
  1773.                 color.grep.external
  1774.                 color.grep.match
  1775.                 color.interactive
  1776.                 color.interactive.header
  1777.                 color.interactive.help
  1778.                 color.interactive.prompt
  1779.                 color.pager
  1780.                 color.showbranch
  1781.                 color.status
  1782.                 color.status.added
  1783.                 color.status.changed
  1784.                 color.status.header
  1785.                 color.status.nobranch
  1786.                 color.status.untracked
  1787.                 color.status.updated
  1788.                 color.ui
  1789.                 commit.template
  1790.                 core.autocrlf
  1791.                 core.bare
  1792.                 core.compression
  1793.                 core.createObject
  1794.                 core.deltaBaseCacheLimit
  1795.                 core.editor
  1796.                 core.excludesfile
  1797.                 core.fileMode
  1798.                 core.fsyncobjectfiles
  1799.                 core.gitProxy
  1800.                 core.ignoreCygwinFSTricks
  1801.                 core.ignoreStat
  1802.                 core.logAllRefUpdates
  1803.                 core.loosecompression
  1804.                 core.packedGitLimit
  1805.                 core.packedGitWindowSize
  1806.                 core.pager
  1807.                 core.preferSymlinkRefs
  1808.                 core.preloadindex
  1809.                 core.quotepath
  1810.                 core.repositoryFormatVersion
  1811.                 core.safecrlf
  1812.                 core.sharedRepository
  1813.                 core.symlinks
  1814.                 core.trustctime
  1815.                 core.warnAmbiguousRefs
  1816.                 core.whitespace
  1817.                 core.worktree
  1818.                 diff.autorefreshindex
  1819.                 diff.external
  1820.                 diff.mnemonicprefix
  1821.                 diff.renameLimit
  1822.                 diff.renameLimit.
  1823.                 diff.renames
  1824.                 diff.suppressBlankEmpty
  1825.                 diff.tool
  1826.                 diff.wordRegex
  1827.                 difftool.
  1828.                 difftool.prompt
  1829.                 fetch.unpackLimit
  1830.                 format.attach
  1831.                 format.cc
  1832.                 format.headers
  1833.                 format.numbered
  1834.                 format.pretty
  1835.                 format.signoff
  1836.                 format.subjectprefix
  1837.                 format.suffix
  1838.                 format.thread
  1839.                 gc.aggressiveWindow
  1840.                 gc.auto
  1841.                 gc.autopacklimit
  1842.                 gc.packrefs
  1843.                 gc.pruneexpire
  1844.                 gc.reflogexpire
  1845.                 gc.reflogexpireunreachable
  1846.                 gc.rerereresolved
  1847.                 gc.rerereunresolved
  1848.                 gitcvs.allbinary
  1849.                 gitcvs.commitmsgannotation
  1850.                 gitcvs.dbTableNamePrefix
  1851.                 gitcvs.dbdriver
  1852.                 gitcvs.dbname
  1853.                 gitcvs.dbpass
  1854.                 gitcvs.dbuser
  1855.                 gitcvs.enabled
  1856.                 gitcvs.logfile
  1857.                 gitcvs.usecrlfattr
  1858.                 guitool.
  1859.                 gui.blamehistoryctx
  1860.                 gui.commitmsgwidth
  1861.                 gui.copyblamethreshold
  1862.                 gui.diffcontext
  1863.                 gui.encoding
  1864.                 gui.fastcopyblame
  1865.                 gui.matchtrackingbranch
  1866.                 gui.newbranchtemplate
  1867.                 gui.pruneduringfetch
  1868.                 gui.spellingdictionary
  1869.                 gui.trustmtime
  1870.                 help.autocorrect
  1871.                 help.browser
  1872.                 help.format
  1873.                 http.lowSpeedLimit
  1874.                 http.lowSpeedTime
  1875.                 http.maxRequests
  1876.                 http.noEPSV
  1877.                 http.proxy
  1878.                 http.sslCAInfo
  1879.                 http.sslCAPath
  1880.                 http.sslCert
  1881.                 http.sslKey
  1882.                 http.sslVerify
  1883.                 i18n.commitEncoding
  1884.                 i18n.logOutputEncoding
  1885.                 imap.folder
  1886.                 imap.host
  1887.                 imap.pass
  1888.                 imap.port
  1889.                 imap.preformattedHTML
  1890.                 imap.sslverify
  1891.                 imap.tunnel
  1892.                 imap.user
  1893.                 instaweb.browser
  1894.                 instaweb.httpd
  1895.                 instaweb.local
  1896.                 instaweb.modulepath
  1897.                 instaweb.port
  1898.                 interactive.singlekey
  1899.                 log.date
  1900.                 log.showroot
  1901.                 mailmap.file
  1902.                 man.
  1903.                 man.viewer
  1904.                 merge.conflictstyle
  1905.                 merge.log
  1906.                 merge.renameLimit
  1907.                 merge.stat
  1908.                 merge.tool
  1909.                 merge.verbosity
  1910.                 mergetool.
  1911.                 mergetool.keepBackup
  1912.                 mergetool.prompt
  1913.                 pack.compression
  1914.                 pack.deltaCacheLimit
  1915.                 pack.deltaCacheSize
  1916.                 pack.depth
  1917.                 pack.indexVersion
  1918.                 pack.packSizeLimit
  1919.                 pack.threads
  1920.                 pack.window
  1921.                 pack.windowMemory
  1922.                 pager.
  1923.                 pull.octopus
  1924.                 pull.twohead
  1925.                 push.default
  1926.                 rebase.stat
  1927.                 receive.denyCurrentBranch
  1928.                 receive.denyDeletes
  1929.                 receive.denyNonFastForwards
  1930.                 receive.fsckObjects
  1931.                 receive.unpackLimit
  1932.                 repack.usedeltabaseoffset
  1933.                 rerere.autoupdate
  1934.                 rerere.enabled
  1935.                 sendemail.aliasesfile
  1936.                 sendemail.aliasesfiletype
  1937.                 sendemail.bcc
  1938.                 sendemail.cc
  1939.                 sendemail.cccmd
  1940.                 sendemail.chainreplyto
  1941.                 sendemail.confirm
  1942.                 sendemail.envelopesender
  1943.                 sendemail.multiedit
  1944.                 sendemail.signedoffbycc
  1945.                 sendemail.smtpencryption
  1946.                 sendemail.smtppass
  1947.                 sendemail.smtpserver
  1948.                 sendemail.smtpserverport
  1949.                 sendemail.smtpuser
  1950.                 sendemail.suppresscc
  1951.                 sendemail.suppressfrom
  1952.                 sendemail.thread
  1953.                 sendemail.to
  1954.                 sendemail.validate
  1955.                 showbranch.default
  1956.                 status.relativePaths
  1957.                 status.showUntrackedFiles
  1958.                 tar.umask
  1959.                 transfer.unpackLimit
  1960.                 url.
  1961.                 user.email
  1962.                 user.name
  1963.                 user.signingkey
  1964.                 web.browser
  1965.                 branch. remote.
  1966.         "
  1967. }
  1968.  
  1969. _git_remote ()
  1970. {
  1971.         local subcommands="add rename rm show prune update set-head"
  1972.         local subcommand="$(__git_find_on_cmdline "$subcommands")"
  1973.         if [ -z "$subcommand" ]; then
  1974.                 __gitcomp "$subcommands"
  1975.                 return
  1976.         fi
  1977.  
  1978.         case "$subcommand" in
  1979.         rename|rm|show|prune)
  1980.                 __gitcomp "$(__git_remotes)"
  1981.                 ;;
  1982.         update)
  1983.                 local i c='' IFS=$'\n'
  1984.                 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
  1985.                         i="${i#remotes.}"
  1986.                         c="$c ${i/ */}"
  1987.                 done
  1988.                 __gitcomp "$c"
  1989.                 ;;
  1990.         *)
  1991.                 COMPREPLY=()
  1992.                 ;;
  1993.         esac
  1994. }
  1995.  
  1996. _git_replace ()
  1997. {
  1998.         __gitcomp "$(__git_refs)"
  1999. }
  2000.  
  2001. _git_reset ()
  2002. {
  2003.         __git_has_doubledash && return
  2004.  
  2005.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2006.         case "$cur" in
  2007.         --*)
  2008.                 __gitcomp "--merge --mixed --hard --soft --patch"
  2009.                 return
  2010.                 ;;
  2011.         esac
  2012.         __gitcomp "$(__git_refs)"
  2013. }
  2014.  
  2015. _git_revert ()
  2016. {
  2017.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2018.         case "$cur" in
  2019.         --*)
  2020.                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
  2021.                 return
  2022.                 ;;
  2023.         esac
  2024.         __gitcomp "$(__git_refs)"
  2025. }
  2026.  
  2027. _git_rm ()
  2028. {
  2029.         __git_has_doubledash && return
  2030.  
  2031.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2032.         case "$cur" in
  2033.         --*)
  2034.                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
  2035.                 return
  2036.                 ;;
  2037.         esac
  2038.         COMPREPLY=()
  2039. }
  2040.  
  2041. _git_shortlog ()
  2042. {
  2043.         __git_has_doubledash && return
  2044.  
  2045.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2046.         case "$cur" in
  2047.         --*)
  2048.                 __gitcomp "
  2049.                         $__git_log_common_options
  2050.                         $__git_log_shortlog_options
  2051.                         --numbered --summary
  2052.                         "
  2053.                 return
  2054.                 ;;
  2055.         esac
  2056.         __git_complete_revlist
  2057. }
  2058.  
  2059. _git_show ()
  2060. {
  2061.         __git_has_doubledash && return
  2062.  
  2063.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2064.         case "$cur" in
  2065.         --pretty=*)
  2066.                 __gitcomp "$__git_log_pretty_formats
  2067.                         " "" "${cur##--pretty=}"
  2068.                 return
  2069.                 ;;
  2070.         --format=*)
  2071.                 __gitcomp "$__git_log_pretty_formats
  2072.                         " "" "${cur##--format=}"
  2073.                 return
  2074.                 ;;
  2075.         --*)
  2076.                 __gitcomp "--pretty= --format= --abbrev-commit --oneline
  2077.                         $__git_diff_common_options
  2078.                         "
  2079.                 return
  2080.                 ;;
  2081.         esac
  2082.         __git_complete_file
  2083. }
  2084.  
  2085. _git_show_branch ()
  2086. {
  2087.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2088.         case "$cur" in
  2089.         --*)
  2090.                 __gitcomp "
  2091.                         --all --remotes --topo-order --current --more=
  2092.                         --list --independent --merge-base --no-name
  2093.                         --color --no-color
  2094.                         --sha1-name --sparse --topics --reflog
  2095.                         "
  2096.                 return
  2097.                 ;;
  2098.         esac
  2099.         __git_complete_revlist
  2100. }
  2101.  
  2102. _git_stash ()
  2103. {
  2104.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2105.         local save_opts='--keep-index --no-keep-index --quiet --patch'
  2106.         local subcommands='save list show apply clear drop pop create branch'
  2107.         local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2108.         if [ -z "$subcommand" ]; then
  2109.                 case "$cur" in
  2110.                 --*)
  2111.                         __gitcomp "$save_opts"
  2112.                         ;;
  2113.                 *)
  2114.                         if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
  2115.                                 __gitcomp "$subcommands"
  2116.                         else
  2117.                                 COMPREPLY=()
  2118.                         fi
  2119.                         ;;
  2120.                 esac
  2121.         else
  2122.                 case "$subcommand,$cur" in
  2123.                 save,--*)
  2124.                         __gitcomp "$save_opts"
  2125.                         ;;
  2126.                 apply,--*|pop,--*)
  2127.                         __gitcomp "--index --quiet"
  2128.                         ;;
  2129.                 show,--*|drop,--*|branch,--*)
  2130.                         COMPREPLY=()
  2131.                         ;;
  2132.                 show,*|apply,*|drop,*|pop,*|branch,*)
  2133.                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
  2134.                                         | sed -n -e 's/:.*//p')"
  2135.                         ;;
  2136.                 *)
  2137.                         COMPREPLY=()
  2138.                         ;;
  2139.                 esac
  2140.         fi
  2141. }
  2142.  
  2143. _git_submodule ()
  2144. {
  2145.         __git_has_doubledash && return
  2146.  
  2147.         local subcommands="add status init update summary foreach sync"
  2148.         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
  2149.                 local cur="${COMP_WORDS[COMP_CWORD]}"
  2150.                 case "$cur" in
  2151.                 --*)
  2152.                         __gitcomp "--quiet --cached"
  2153.                         ;;
  2154.                 *)
  2155.                         __gitcomp "$subcommands"
  2156.                         ;;
  2157.                 esac
  2158.                 return
  2159.         fi
  2160. }
  2161.  
  2162. _git_svn ()
  2163. {
  2164.         local subcommands="
  2165.                 init fetch clone rebase dcommit log find-rev
  2166.                 set-tree commit-diff info create-ignore propget
  2167.                 proplist show-ignore show-externals branch tag blame
  2168.                 migrate mkdirs reset gc
  2169.                 "
  2170.         local subcommand="$(__git_find_on_cmdline "$subcommands")"
  2171.         if [ -z "$subcommand" ]; then
  2172.                 __gitcomp "$subcommands"
  2173.         else
  2174.                 local remote_opts="--username= --config-dir= --no-auth-cache"
  2175.                 local fc_opts="
  2176.                         --follow-parent --authors-file= --repack=
  2177.                         --no-metadata --use-svm-props --use-svnsync-props
  2178.                         --log-window-size= --no-checkout --quiet
  2179.                         --repack-flags --use-log-author --localtime
  2180.                         --ignore-paths= $remote_opts
  2181.                         "
  2182.                 local init_opts="
  2183.                         --template= --shared= --trunk= --tags=
  2184.                         --branches= --stdlayout --minimize-url
  2185.                         --no-metadata --use-svm-props --use-svnsync-props
  2186.                         --rewrite-root= --prefix= --use-log-author
  2187.                         --add-author-from $remote_opts
  2188.                         "
  2189.                 local cmt_opts="
  2190.                         --edit --rmdir --find-copies-harder --copy-similarity=
  2191.                         "
  2192.  
  2193.                 local cur="${COMP_WORDS[COMP_CWORD]}"
  2194.                 case "$subcommand,$cur" in
  2195.                 fetch,--*)
  2196.                         __gitcomp "--revision= --fetch-all $fc_opts"
  2197.                         ;;
  2198.                 clone,--*)
  2199.                         __gitcomp "--revision= $fc_opts $init_opts"
  2200.                         ;;
  2201.                 init,--*)
  2202.                         __gitcomp "$init_opts"
  2203.                         ;;
  2204.                 dcommit,--*)
  2205.                         __gitcomp "
  2206.                                 --merge --strategy= --verbose --dry-run
  2207.                                 --fetch-all --no-rebase --commit-url
  2208.                                 --revision $cmt_opts $fc_opts
  2209.                                 "
  2210.                         ;;
  2211.                 set-tree,--*)
  2212.                         __gitcomp "--stdin $cmt_opts $fc_opts"
  2213.                         ;;
  2214.                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
  2215.                 show-externals,--*|mkdirs,--*)
  2216.                         __gitcomp "--revision="
  2217.                         ;;
  2218.                 log,--*)
  2219.                         __gitcomp "
  2220.                                 --limit= --revision= --verbose --incremental
  2221.                                 --oneline --show-commit --non-recursive
  2222.                                 --authors-file= --color
  2223.                                 "
  2224.                         ;;
  2225.                 rebase,--*)
  2226.                         __gitcomp "
  2227.                                 --merge --verbose --strategy= --local
  2228.                                 --fetch-all --dry-run $fc_opts
  2229.                                 "
  2230.                         ;;
  2231.                 commit-diff,--*)
  2232.                         __gitcomp "--message= --file= --revision= $cmt_opts"
  2233.                         ;;
  2234.                 info,--*)
  2235.                         __gitcomp "--url"
  2236.                         ;;
  2237.                 branch,--*)
  2238.                         __gitcomp "--dry-run --message --tag"
  2239.                         ;;
  2240.                 tag,--*)
  2241.                         __gitcomp "--dry-run --message"
  2242.                         ;;
  2243.                 blame,--*)
  2244.                         __gitcomp "--git-format"
  2245.                         ;;
  2246.                 migrate,--*)
  2247.                         __gitcomp "
  2248.                                 --config-dir= --ignore-paths= --minimize
  2249.                                 --no-auth-cache --username=
  2250.                                 "
  2251.                         ;;
  2252.                 reset,--*)
  2253.                         __gitcomp "--revision= --parent"
  2254.                         ;;
  2255.                 *)
  2256.                         COMPREPLY=()
  2257.                         ;;
  2258.                 esac
  2259.         fi
  2260. }
  2261.  
  2262. _git_tag ()
  2263. {
  2264.         local i c=1 f=0
  2265.         while [ $c -lt $COMP_CWORD ]; do
  2266.                 i="${COMP_WORDS[c]}"
  2267.                 case "$i" in
  2268.                 -d|-v)
  2269.                         __gitcomp "$(__git_tags)"
  2270.                         return
  2271.                         ;;
  2272.                 -f)
  2273.                         f=1
  2274.                         ;;
  2275.                 esac
  2276.                 c=$((++c))
  2277.         done
  2278.  
  2279.         case "${COMP_WORDS[COMP_CWORD-1]}" in
  2280.         -m|-F)
  2281.                 COMPREPLY=()
  2282.                 ;;
  2283.         -*|tag)
  2284.                 if [ $f = 1 ]; then
  2285.                         __gitcomp "$(__git_tags)"
  2286.                 else
  2287.                         COMPREPLY=()
  2288.                 fi
  2289.                 ;;
  2290.         *)
  2291.                 __gitcomp "$(__git_refs)"
  2292.                 ;;
  2293.         esac
  2294. }
  2295.  
  2296. _git ()
  2297. {
  2298.         local i c=1 command __git_dir
  2299.  
  2300.         while [ $c -lt $COMP_CWORD ]; do
  2301.                 i="${COMP_WORDS[c]}"
  2302.                 case "$i" in
  2303.                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  2304.                 --bare)      __git_dir="." ;;
  2305.                 --version|-p|--paginate) ;;
  2306.                 --help) command="help"; break ;;
  2307.                 *) command="$i"; break ;;
  2308.                 esac
  2309.                 c=$((++c))
  2310.         done
  2311.  
  2312.         if [ -z "$command" ]; then
  2313.                 case "${COMP_WORDS[COMP_CWORD]}" in
  2314.                 --*)   __gitcomp "
  2315.                         --paginate
  2316.                         --no-pager
  2317.                         --git-dir=
  2318.                         --bare
  2319.                         --version
  2320.                         --exec-path
  2321.                         --html-path
  2322.                         --work-tree=
  2323.                         --help
  2324.                         "
  2325.                         ;;
  2326.                 *)     __git_compute_porcelain_commands
  2327.                        __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
  2328.                 esac
  2329.                 return
  2330.         fi
  2331.  
  2332.         local expansion=$(__git_aliased_command "$command")
  2333.         [ "$expansion" ] && command="$expansion"
  2334.  
  2335.         case "$command" in
  2336.         am)          _git_am ;;
  2337.         add)         _git_add ;;
  2338.         apply)       _git_apply ;;
  2339.         archive)     _git_archive ;;
  2340.         bisect)      _git_bisect ;;
  2341.         bundle)      _git_bundle ;;
  2342.         branch)      _git_branch ;;
  2343.         checkout)    _git_checkout ;;
  2344.         cherry)      _git_cherry ;;
  2345.         cherry-pick) _git_cherry_pick ;;
  2346.         clean)       _git_clean ;;
  2347.         clone)       _git_clone ;;
  2348.         commit)      _git_commit ;;
  2349.         config)      _git_config ;;
  2350.         describe)    _git_describe ;;
  2351.         diff)        _git_diff ;;
  2352.         difftool)    _git_difftool ;;
  2353.         fetch)       _git_fetch ;;
  2354.         format-patch) _git_format_patch ;;
  2355.         fsck)        _git_fsck ;;
  2356.         gc)          _git_gc ;;
  2357.         grep)        _git_grep ;;
  2358.         help)        _git_help ;;
  2359.         init)        _git_init ;;
  2360.         log)         _git_log ;;
  2361.         ls-files)    _git_ls_files ;;
  2362.         ls-remote)   _git_ls_remote ;;
  2363.         ls-tree)     _git_ls_tree ;;
  2364.         merge)       _git_merge;;
  2365.         mergetool)   _git_mergetool;;
  2366.         merge-base)  _git_merge_base ;;
  2367.         mv)          _git_mv ;;
  2368.         name-rev)    _git_name_rev ;;
  2369.         notes)       _git_notes ;;
  2370.         pull)        _git_pull ;;
  2371.         push)        _git_push ;;
  2372.         rebase)      _git_rebase ;;
  2373.         remote)      _git_remote ;;
  2374.         replace)     _git_replace ;;
  2375.         reset)       _git_reset ;;
  2376.         revert)      _git_revert ;;
  2377.         rm)          _git_rm ;;
  2378.         send-email)  _git_send_email ;;
  2379.         shortlog)    _git_shortlog ;;
  2380.         show)        _git_show ;;
  2381.         show-branch) _git_show_branch ;;
  2382.         stash)       _git_stash ;;
  2383.         stage)       _git_add ;;
  2384.         submodule)   _git_submodule ;;
  2385.         svn)         _git_svn ;;
  2386.         tag)         _git_tag ;;
  2387.         whatchanged) _git_log ;;
  2388.         *)           COMPREPLY=() ;;
  2389.         esac
  2390. }
  2391.  
  2392. _gitk ()
  2393. {
  2394.         __git_has_doubledash && return
  2395.  
  2396.         local cur="${COMP_WORDS[COMP_CWORD]}"
  2397.         local g="$(__gitdir)"
  2398.         local merge=""
  2399.         if [ -f "$g/MERGE_HEAD" ]; then
  2400.                 merge="--merge"
  2401.         fi
  2402.         case "$cur" in
  2403.         --*)
  2404.                 __gitcomp "
  2405.                         $__git_log_common_options
  2406.                         $__git_log_gitk_options
  2407.                         $merge
  2408.                         "
  2409.                 return
  2410.                 ;;
  2411.         esac
  2412.         __git_complete_revlist
  2413. }
  2414.  
  2415. complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
  2416.         || complete -o default -o nospace -F _git git
  2417. complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
  2418.         || complete -o default -o nospace -F _gitk gitk
  2419.  
  2420. # The following are necessary only for Cygwin, and only are needed
  2421. # when the user has tab-completed the executable name and consequently
  2422. # included the '.exe' suffix.
  2423. #
  2424. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  2425. complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
  2426.         || complete -o default -o nospace -F _git git.exe
  2427. fi