Skip to content
This repository
Browse code

Let's get this party started

  • Loading branch information...
commit b48c4deba04bd0ca3e5814438ae25133a2822f85 0 parents
Ryan Tomayko authored committed
278 COPYING
... ... @@ -0,0 +1,278 @@
  1 + GNU GENERAL PUBLIC LICENSE
  2 + Version 2, June 1991
  3 +
  4 + Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  5 + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  6 + Everyone is permitted to copy and distribute verbatim copies
  7 + of this license document, but changing it is not allowed.
  8 +
  9 + Preamble
  10 +
  11 + The licenses for most software are designed to take away your
  12 +freedom to share and change it. By contrast, the GNU General Public
  13 +License is intended to guarantee your freedom to share and change free
  14 +software--to make sure the software is free for all its users. This
  15 +General Public License applies to most of the Free Software
  16 +Foundation's software and to any other program whose authors commit to
  17 +using it. (Some other Free Software Foundation software is covered by
  18 +the GNU Lesser General Public License instead.) You can apply it to
  19 +your programs, too.
  20 +
  21 + When we speak of free software, we are referring to freedom, not
  22 +price. Our General Public Licenses are designed to make sure that you
  23 +have the freedom to distribute copies of free software (and charge for
  24 +this service if you wish), that you receive source code or can get it
  25 +if you want it, that you can change the software or use pieces of it
  26 +in new free programs; and that you know you can do these things.
  27 +
  28 + To protect your rights, we need to make restrictions that forbid
  29 +anyone to deny you these rights or to ask you to surrender the rights.
  30 +These restrictions translate to certain responsibilities for you if you
  31 +distribute copies of the software, or if you modify it.
  32 +
  33 + For example, if you distribute copies of such a program, whether
  34 +gratis or for a fee, you must give the recipients all the rights that
  35 +you have. You must make sure that they, too, receive or can get the
  36 +source code. And you must show them these terms so they know their
  37 +rights.
  38 +
  39 + We protect your rights with two steps: (1) copyright the software, and
  40 +(2) offer you this license which gives you legal permission to copy,
  41 +distribute and/or modify the software.
  42 +
  43 + Also, for each author's protection and ours, we want to make certain
  44 +that everyone understands that there is no warranty for this free
  45 +software. If the software is modified by someone else and passed on, we
  46 +want its recipients to know that what they have is not the original, so
  47 +that any problems introduced by others will not reflect on the original
  48 +authors' reputations.
  49 +
  50 + Finally, any free program is threatened constantly by software
  51 +patents. We wish to avoid the danger that redistributors of a free
  52 +program will individually obtain patent licenses, in effect making the
  53 +program proprietary. To prevent this, we have made it clear that any
  54 +patent must be licensed for everyone's free use or not licensed at all.
  55 +
  56 + The precise terms and conditions for copying, distribution and
  57 +modification follow.
  58 +
  59 + GNU GENERAL PUBLIC LICENSE
  60 + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  61 +
  62 + 0. This License applies to any program or other work which contains
  63 +a notice placed by the copyright holder saying it may be distributed
  64 +under the terms of this General Public License. The "Program", below,
  65 +refers to any such program or work, and a "work based on the Program"
  66 +means either the Program or any derivative work under copyright law:
  67 +that is to say, a work containing the Program or a portion of it,
  68 +either verbatim or with modifications and/or translated into another
  69 +language. (Hereinafter, translation is included without limitation in
  70 +the term "modification".) Each licensee is addressed as "you".
  71 +
  72 +Activities other than copying, distribution and modification are not
  73 +covered by this License; they are outside its scope. The act of
  74 +running the Program is not restricted, and the output from the Program
  75 +is covered only if its contents constitute a work based on the
  76 +Program (independent of having been made by running the Program).
  77 +Whether that is true depends on what the Program does.
  78 +
  79 + 1. You may copy and distribute verbatim copies of the Program's
  80 +source code as you receive it, in any medium, provided that you
  81 +conspicuously and appropriately publish on each copy an appropriate
  82 +copyright notice and disclaimer of warranty; keep intact all the
  83 +notices that refer to this License and to the absence of any warranty;
  84 +and give any other recipients of the Program a copy of this License
  85 +along with the Program.
  86 +
  87 +You may charge a fee for the physical act of transferring a copy, and
  88 +you may at your option offer warranty protection in exchange for a fee.
  89 +
  90 + 2. You may modify your copy or copies of the Program or any portion
  91 +of it, thus forming a work based on the Program, and copy and
  92 +distribute such modifications or work under the terms of Section 1
  93 +above, provided that you also meet all of these conditions:
  94 +
  95 + a) You must cause the modified files to carry prominent notices
  96 + stating that you changed the files and the date of any change.
  97 +
  98 + b) You must cause any work that you distribute or publish, that in
  99 + whole or in part contains or is derived from the Program or any
  100 + part thereof, to be licensed as a whole at no charge to all third
  101 + parties under the terms of this License.
  102 +
  103 + c) If the modified program normally reads commands interactively
  104 + when run, you must cause it, when started running for such
  105 + interactive use in the most ordinary way, to print or display an
  106 + announcement including an appropriate copyright notice and a
  107 + notice that there is no warranty (or else, saying that you provide
  108 + a warranty) and that users may redistribute the program under
  109 + these conditions, and telling the user how to view a copy of this
  110 + License. (Exception: if the Program itself is interactive but
  111 + does not normally print such an announcement, your work based on
  112 + the Program is not required to print an announcement.)
  113 +
  114 +These requirements apply to the modified work as a whole. If
  115 +identifiable sections of that work are not derived from the Program,
  116 +and can be reasonably considered independent and separate works in
  117 +themselves, then this License, and its terms, do not apply to those
  118 +sections when you distribute them as separate works. But when you
  119 +distribute the same sections as part of a whole which is a work based
  120 +on the Program, the distribution of the whole must be on the terms of
  121 +this License, whose permissions for other licensees extend to the
  122 +entire whole, and thus to each and every part regardless of who wrote it.
  123 +
  124 +Thus, it is not the intent of this section to claim rights or contest
  125 +your rights to work written entirely by you; rather, the intent is to
  126 +exercise the right to control the distribution of derivative or
  127 +collective works based on the Program.
  128 +
  129 +In addition, mere aggregation of another work not based on the Program
  130 +with the Program (or with a work based on the Program) on a volume of
  131 +a storage or distribution medium does not bring the other work under
  132 +the scope of this License.
  133 +
  134 + 3. You may copy and distribute the Program (or a work based on it,
  135 +under Section 2) in object code or executable form under the terms of
  136 +Sections 1 and 2 above provided that you also do one of the following:
  137 +
  138 + a) Accompany it with the complete corresponding machine-readable
  139 + source code, which must be distributed under the terms of Sections
  140 + 1 and 2 above on a medium customarily used for software interchange; or,
  141 +
  142 + b) Accompany it with a written offer, valid for at least three
  143 + years, to give any third party, for a charge no more than your
  144 + cost of physically performing source distribution, a complete
  145 + machine-readable copy of the corresponding source code, to be
  146 + distributed under the terms of Sections 1 and 2 above on a medium
  147 + customarily used for software interchange; or,
  148 +
  149 + c) Accompany it with the information you received as to the offer
  150 + to distribute corresponding source code. (This alternative is
  151 + allowed only for noncommercial distribution and only if you
  152 + received the program in object code or executable form with such
  153 + an offer, in accord with Subsection b above.)
  154 +
  155 +The source code for a work means the preferred form of the work for
  156 +making modifications to it. For an executable work, complete source
  157 +code means all the source code for all modules it contains, plus any
  158 +associated interface definition files, plus the scripts used to
  159 +control compilation and installation of the executable. However, as a
  160 +special exception, the source code distributed need not include
  161 +anything that is normally distributed (in either source or binary
  162 +form) with the major components (compiler, kernel, and so on) of the
  163 +operating system on which the executable runs, unless that component
  164 +itself accompanies the executable.
  165 +
  166 +If distribution of executable or object code is made by offering
  167 +access to copy from a designated place, then offering equivalent
  168 +access to copy the source code from the same place counts as
  169 +distribution of the source code, even though third parties are not
  170 +compelled to copy the source along with the object code.
  171 +
  172 + 4. You may not copy, modify, sublicense, or distribute the Program
  173 +except as expressly provided under this License. Any attempt
  174 +otherwise to copy, modify, sublicense or distribute the Program is
  175 +void, and will automatically terminate your rights under this License.
  176 +However, parties who have received copies, or rights, from you under
  177 +this License will not have their licenses terminated so long as such
  178 +parties remain in full compliance.
  179 +
  180 + 5. You are not required to accept this License, since you have not
  181 +signed it. However, nothing else grants you permission to modify or
  182 +distribute the Program or its derivative works. These actions are
  183 +prohibited by law if you do not accept this License. Therefore, by
  184 +modifying or distributing the Program (or any work based on the
  185 +Program), you indicate your acceptance of this License to do so, and
  186 +all its terms and conditions for copying, distributing or modifying
  187 +the Program or works based on it.
  188 +
  189 + 6. Each time you redistribute the Program (or any work based on the
  190 +Program), the recipient automatically receives a license from the
  191 +original licensor to copy, distribute or modify the Program subject to
  192 +these terms and conditions. You may not impose any further
  193 +restrictions on the recipients' exercise of the rights granted herein.
  194 +You are not responsible for enforcing compliance by third parties to
  195 +this License.
  196 +
  197 + 7. If, as a consequence of a court judgment or allegation of patent
  198 +infringement or for any other reason (not limited to patent issues),
  199 +conditions are imposed on you (whether by court order, agreement or
  200 +otherwise) that contradict the conditions of this License, they do not
  201 +excuse you from the conditions of this License. If you cannot
  202 +distribute so as to satisfy simultaneously your obligations under this
  203 +License and any other pertinent obligations, then as a consequence you
  204 +may not distribute the Program at all. For example, if a patent
  205 +license would not permit royalty-free redistribution of the Program by
  206 +all those who receive copies directly or indirectly through you, then
  207 +the only way you could satisfy both it and this License would be to
  208 +refrain entirely from distribution of the Program.
  209 +
  210 +If any portion of this section is held invalid or unenforceable under
  211 +any particular circumstance, the balance of the section is intended to
  212 +apply and the section as a whole is intended to apply in other
  213 +circumstances.
  214 +
  215 +It is not the purpose of this section to induce you to infringe any
  216 +patents or other property right claims or to contest validity of any
  217 +such claims; this section has the sole purpose of protecting the
  218 +integrity of the free software distribution system, which is
  219 +implemented by public license practices. Many people have made
  220 +generous contributions to the wide range of software distributed
  221 +through that system in reliance on consistent application of that
  222 +system; it is up to the author/donor to decide if he or she is willing
  223 +to distribute software through any other system and a licensee cannot
  224 +impose that choice.
  225 +
  226 +This section is intended to make thoroughly clear what is believed to
  227 +be a consequence of the rest of this License.
  228 +
  229 + 8. If the distribution and/or use of the Program is restricted in
  230 +certain countries either by patents or by copyrighted interfaces, the
  231 +original copyright holder who places the Program under this License
  232 +may add an explicit geographical distribution limitation excluding
  233 +those countries, so that distribution is permitted only in or among
  234 +countries not thus excluded. In such case, this License incorporates
  235 +the limitation as if written in the body of this License.
  236 +
  237 + 9. The Free Software Foundation may publish revised and/or new versions
  238 +of the General Public License from time to time. Such new versions will
  239 +be similar in spirit to the present version, but may differ in detail to
  240 +address new problems or concerns.
  241 +
  242 +Each version is given a distinguishing version number. If the Program
  243 +specifies a version number of this License which applies to it and "any
  244 +later version", you have the option of following the terms and conditions
  245 +either of that version or of any later version published by the Free
  246 +Software Foundation. If the Program does not specify a version number of
  247 +this License, you may choose any version ever published by the Free Software
  248 +Foundation.
  249 +
  250 + 10. If you wish to incorporate parts of the Program into other free
  251 +programs whose distribution conditions are different, write to the author
  252 +to ask for permission. For software which is copyrighted by the Free
  253 +Software Foundation, write to the Free Software Foundation; we sometimes
  254 +make exceptions for this. Our decision will be guided by the two goals
  255 +of preserving the free status of all derivatives of our free software and
  256 +of promoting the sharing and reuse of software generally.
  257 +
  258 + NO WARRANTY
  259 +
  260 + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  261 +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
  262 +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  263 +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  264 +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  265 +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
  266 +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
  267 +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  268 +REPAIR OR CORRECTION.
  269 +
  270 + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  271 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  272 +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  273 +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  274 +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  275 +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  276 +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  277 +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  278 +POSSIBILITY OF SUCH DAMAGES.
15 Makefile
... ... @@ -0,0 +1,15 @@
  1 +SHELL = /bin/sh
  2 +PREFIX = /usr/local
  3 +EXEC_DIR = $(PREFIX)/bin
  4 +
  5 +all: git-sh
  6 +
  7 +git-sh: git-sh.bash git-completion.bash git-sh-config.bash
  8 + cat $^ > git-sh
  9 + chmod 0755 git-sh
  10 +
  11 +install: git-sh
  12 + install -m 0755 git-sh $(EXEC_DIR)
  13 +
  14 +clean:
  15 + rm git-sh
86 README.markdown
Source Rendered
... ... @@ -0,0 +1,86 @@
  1 +git-sh
  2 +======
  3 +
  4 +A customized bash shell suitable for git work.
  5 +
  6 +The `git-sh` command starts an interactive shell tweaked for heavy git
  7 +interaction:
  8 +
  9 + * Makes all git command porcelains available as top-level command aliases.
  10 + * Custom prompt with branch and current repository
  11 + * Customizable via ~/.gitshrc file (add aliases, change prompt, etc.)
  12 + * Shawn O. Pearce's bash completion support built-in and works with
  13 + aliases.
  14 + * Respects `~/.bashrc` and `~/.inputrc` configuration.
  15 +
  16 +Installation
  17 +------------
  18 +
  19 +I suppose we can assume you have git installed:
  20 +
  21 + $ git clone git://github.com/rtomayko/git-sh.git
  22 + $ cd git-sh
  23 + $ make
  24 + $ sudo make install
  25 +
  26 +The `make install` command copies the `git-sh` executable to
  27 +`/usr/local/bin`. Use the `PREFIX` environment variable to specify
  28 +a different location (or just copy and chmod the `git-sh` file).
  29 +
  30 +If you'd like to be able to run `git sh` instead of `git-sh`, use
  31 +the following to add a command alias in `~/.gitconfig`:
  32 +
  33 + $ git-sh --configure
  34 + $ git sh
  35 +
  36 +Basic Usage
  37 +-----------
  38 +
  39 +I typically change into a git working copy before starting the shell:
  40 +
  41 + $ cd some-git-repo
  42 + $ git sh
  43 + master!some-git-repo>
  44 +
  45 +The shell's default prompt shows the current branch, bang, and the relative
  46 +path to the current working directory from the nearest git working copy.
  47 +
  48 +Most git commands can be executed directly:
  49 +
  50 + master!some-git-repo> checkout -b new-branch
  51 + new-branch!some-git-repo> log -p
  52 + new-branch!some-git-repo> rebase -i HEAD~10
  53 +
  54 +IMPORTANT: `rm`, `mv`, and `diff` are aliased to their git counterparts.
  55 +Qualify the command (e.g., `/bin/rm`) to use system versions.
  56 +
  57 +Customizing
  58 +-----------
  59 +
  60 +If the `~/.gitshrc` file exists, it is sourced as the very last thing the
  61 +shell does before becoming interactive. I've included my personal
  62 +[`~/.gitshrc`][1] in the distribution as an example.
  63 +
  64 +[1]: gitshrc-example.bash "Ryan's ~/.gitshrc file"
  65 +
  66 +Note also that your `~/.bashrc` file is sourced into the shell as well so
  67 +any customization made there not explicitly overridden by `git-sh` should
  68 +be available.
  69 +
  70 +Help
  71 +----
  72 +
  73 +The `help` command shows git's help output followed by a list of custom
  74 +aliases from your `~/.gitshrc` file:
  75 +
  76 + master!some-git-repo> help
  77 +
  78 +License
  79 +-------
  80 +
  81 +Copyright (C) 2008 Ryan Tomayko <r@tomayko.com>
  82 +Copyright (C) 2006, 2007 Shawn O. Pearce <spearce@spearce.org>
  83 +
  84 +This program is free software; you can redistribute it and/or modify it
  85 +under the terms of the GNU General Public License, version 2, as published
  86 +by the Free Software Foundation.
1,294 git-completion.bash
... ... @@ -0,0 +1,1294 @@
  1 +#
  2 +# bash completion support for core Git.
  3 +#
  4 +# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  5 +# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  6 +# Distributed under the GNU General Public License, version 2.0.
  7 +#
  8 +# The contained completion routines provide support for completing:
  9 +#
  10 +# *) local and remote branch names
  11 +# *) local and remote tag names
  12 +# *) .git/remotes file names
  13 +# *) git 'subcommands'
  14 +# *) tree paths within 'ref:path/to/file' expressions
  15 +# *) common --long-options
  16 +#
  17 +# To use these routines:
  18 +#
  19 +# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  20 +# 2) Added the following line to your .bashrc:
  21 +# source ~/.git-completion.sh
  22 +#
  23 +# 3) You may want to make sure the git executable is available
  24 +# in your PATH before this script is sourced, as some caching
  25 +# is performed while the script loads. If git isn't found
  26 +# at source time then all lookups will be done on demand,
  27 +# which may be slightly slower.
  28 +#
  29 +# 4) Consider changing your PS1 to also show the current branch:
  30 +# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  31 +#
  32 +# The argument to __git_ps1 will be displayed only if you
  33 +# are currently in a git repository. The %s token will be
  34 +# the name of the current branch.
  35 +#
  36 +# To submit patches:
  37 +#
  38 +# *) Read Documentation/SubmittingPatches
  39 +# *) Send all patches to the current maintainer:
  40 +#
  41 +# "Shawn O. Pearce" <spearce@spearce.org>
  42 +#
  43 +# *) Always CC the Git mailing list:
  44 +#
  45 +# git@vger.kernel.org
  46 +#
  47 +
  48 +__gitdir ()
  49 +{
  50 + if [ -z "$1" ]; then
  51 + if [ -n "$__git_dir" ]; then
  52 + echo "$__git_dir"
  53 + elif [ -d .git ]; then
  54 + echo .git
  55 + else
  56 + git rev-parse --git-dir 2>/dev/null
  57 + fi
  58 + elif [ -d "$1/.git" ]; then
  59 + echo "$1/.git"
  60 + else
  61 + echo "$1"
  62 + fi
  63 +}
  64 +
  65 +__git_ps1 ()
  66 +{
  67 + local g="$(git rev-parse --git-dir 2>/dev/null)"
  68 + if [ -n "$g" ]; then
  69 + local r
  70 + local b
  71 + if [ -d "$g/../.dotest" ]
  72 + then
  73 + r="|AM/REBASE"
  74 + b="$(git symbolic-ref HEAD 2>/dev/null)"
  75 + elif [ -f "$g/.dotest-merge/interactive" ]
  76 + then
  77 + r="|REBASE-i"
  78 + b="$(cat $g/.dotest-merge/head-name)"
  79 + elif [ -d "$g/.dotest-merge" ]
  80 + then
  81 + r="|REBASE-m"
  82 + b="$(cat $g/.dotest-merge/head-name)"
  83 + elif [ -f "$g/MERGE_HEAD" ]
  84 + then
  85 + r="|MERGING"
  86 + b="$(git symbolic-ref HEAD 2>/dev/null)"
  87 + else
  88 + if [ -f $g/BISECT_LOG ]
  89 + then
  90 + r="|BISECTING"
  91 + fi
  92 + if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
  93 + then
  94 + b="$(cut -c1-7 $g/HEAD)..."
  95 + fi
  96 + fi
  97 +
  98 + if [ -n "$1" ]; then
  99 + printf "$1" "${b##refs/heads/}$r"
  100 + else
  101 + printf " (%s)" "${b##refs/heads/}$r"
  102 + fi
  103 + fi
  104 +}
  105 +
  106 +__gitcomp ()
  107 +{
  108 + local all c s=$'\n' IFS=' '$'\t'$'\n'
  109 + local cur="${COMP_WORDS[COMP_CWORD]}"
  110 + if [ $# -gt 2 ]; then
  111 + cur="$3"
  112 + fi
  113 + for c in $1; do
  114 + case "$c$4" in
  115 + --*=*) all="$all$c$4$s" ;;
  116 + *.) all="$all$c$4$s" ;;
  117 + *) all="$all$c$4 $s" ;;
  118 + esac
  119 + done
  120 + IFS=$s
  121 + COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
  122 + return
  123 +}
  124 +
  125 +__git_heads ()
  126 +{
  127 + local cmd i is_hash=y dir="$(__gitdir "$1")"
  128 + if [ -d "$dir" ]; then
  129 + for i in $(git --git-dir="$dir" \
  130 + for-each-ref --format='%(refname)' \
  131 + refs/heads ); do
  132 + echo "${i#refs/heads/}"
  133 + done
  134 + return
  135 + fi
  136 + for i in $(git-ls-remote "$1" 2>/dev/null); do
  137 + case "$is_hash,$i" in
  138 + y,*) is_hash=n ;;
  139 + n,*^{}) is_hash=y ;;
  140 + n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  141 + n,*) is_hash=y; echo "$i" ;;
  142 + esac
  143 + done
  144 +}
  145 +
  146 +__git_tags ()
  147 +{
  148 + local cmd i is_hash=y dir="$(__gitdir "$1")"
  149 + if [ -d "$dir" ]; then
  150 + for i in $(git --git-dir="$dir" \
  151 + for-each-ref --format='%(refname)' \
  152 + refs/tags ); do
  153 + echo "${i#refs/tags/}"
  154 + done
  155 + return
  156 + fi
  157 + for i in $(git-ls-remote "$1" 2>/dev/null); do
  158 + case "$is_hash,$i" in
  159 + y,*) is_hash=n ;;
  160 + n,*^{}) is_hash=y ;;
  161 + n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  162 + n,*) is_hash=y; echo "$i" ;;
  163 + esac
  164 + done
  165 +}
  166 +
  167 +__git_refs ()
  168 +{
  169 + local cmd i is_hash=y dir="$(__gitdir "$1")"
  170 + if [ -d "$dir" ]; then
  171 + if [ -e "$dir/HEAD" ]; then echo HEAD; fi
  172 + for i in $(git --git-dir="$dir" \
  173 + for-each-ref --format='%(refname)' \
  174 + refs/tags refs/heads refs/remotes); do
  175 + case "$i" in
  176 + refs/tags/*) echo "${i#refs/tags/}" ;;
  177 + refs/heads/*) echo "${i#refs/heads/}" ;;
  178 + refs/remotes/*) echo "${i#refs/remotes/}" ;;
  179 + *) echo "$i" ;;
  180 + esac
  181 + done
  182 + return
  183 + fi
  184 + for i in $(git-ls-remote "$dir" 2>/dev/null); do
  185 + case "$is_hash,$i" in
  186 + y,*) is_hash=n ;;
  187 + n,*^{}) is_hash=y ;;
  188 + n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  189 + n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  190 + n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
  191 + n,*) is_hash=y; echo "$i" ;;
  192 + esac
  193 + done
  194 +}
  195 +
  196 +__git_refs2 ()
  197 +{
  198 + local i
  199 + for i in $(__git_refs "$1"); do
  200 + echo "$i:$i"
  201 + done
  202 +}
  203 +
  204 +__git_refs_remotes ()
  205 +{
  206 + local cmd i is_hash=y
  207 + for i in $(git-ls-remote "$1" 2>/dev/null); do
  208 + case "$is_hash,$i" in
  209 + n,refs/heads/*)
  210 + is_hash=y
  211 + echo "$i:refs/remotes/$1/${i#refs/heads/}"
  212 + ;;
  213 + y,*) is_hash=n ;;
  214 + n,*^{}) is_hash=y ;;
  215 + n,refs/tags/*) is_hash=y;;
  216 + n,*) is_hash=y; ;;
  217 + esac
  218 + done
  219 +}
  220 +
  221 +__git_remotes ()
  222 +{
  223 + local i ngoff IFS=$'\n' d="$(__gitdir)"
  224 + shopt -q nullglob || ngoff=1
  225 + shopt -s nullglob
  226 + for i in "$d/remotes"/*; do
  227 + echo ${i#$d/remotes/}
  228 + done
  229 + [ "$ngoff" ] && shopt -u nullglob
  230 + for i in $(git --git-dir="$d" config --list); do
  231 + case "$i" in
  232 + remote.*.url=*)
  233 + i="${i#remote.}"
  234 + echo "${i/.url=*/}"
  235 + ;;
  236 + esac
  237 + done
  238 +}
  239 +
  240 +__git_merge_strategies ()
  241 +{
  242 + if [ -n "$__git_merge_strategylist" ]; then
  243 + echo "$__git_merge_strategylist"
  244 + return
  245 + fi
  246 + sed -n "/^all_strategies='/{
  247 + s/^all_strategies='//
  248 + s/'//
  249 + p
  250 + q
  251 + }" "$(git --exec-path)/git-merge"
  252 +}
  253 +__git_merge_strategylist=
  254 +__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
  255 +
  256 +__git_complete_file ()
  257 +{
  258 + local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
  259 + case "$cur" in
  260 + ?*:*)
  261 + ref="${cur%%:*}"
  262 + cur="${cur#*:}"
  263 + case "$cur" in
  264 + ?*/*)
  265 + pfx="${cur%/*}"
  266 + cur="${cur##*/}"
  267 + ls="$ref:$pfx"
  268 + pfx="$pfx/"
  269 + ;;
  270 + *)
  271 + ls="$ref"
  272 + ;;
  273 + esac
  274 + COMPREPLY=($(compgen -P "$pfx" \
  275 + -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
  276 + | sed '/^100... blob /s,^.* ,,
  277 + /^040000 tree /{
  278 + s,^.* ,,
  279 + s,$,/,
  280 + }
  281 + s/^.* //')" \
  282 + -- "$cur"))
  283 + ;;
  284 + *)
  285 + __gitcomp "$(__git_refs)"
  286 + ;;
  287 + esac
  288 +}
  289 +
  290 +__git_complete_revlist ()
  291 +{
  292 + local pfx cur="${COMP_WORDS[COMP_CWORD]}"
  293 + case "$cur" in
  294 + *...*)
  295 + pfx="${cur%...*}..."
  296 + cur="${cur#*...}"
  297 + __gitcomp "$(__git_refs)" "$pfx" "$cur"
  298 + ;;
  299 + *..*)
  300 + pfx="${cur%..*}.."
  301 + cur="${cur#*..}"
  302 + __gitcomp "$(__git_refs)" "$pfx" "$cur"
  303 + ;;
  304 + *.)
  305 + __gitcomp "$cur."
  306 + ;;
  307 + *)
  308 + __gitcomp "$(__git_refs)"
  309 + ;;
  310 + esac
  311 +}
  312 +
  313 +__git_commands ()
  314 +{
  315 + if [ -n "$__git_commandlist" ]; then
  316 + echo "$__git_commandlist"
  317 + return
  318 + fi
  319 + local i IFS=" "$'\n'
  320 + for i in $(git help -a|egrep '^ ')
  321 + do
  322 + case $i in
  323 + *--*) : helper pattern;;
  324 + applymbox) : ask gittus;;
  325 + applypatch) : ask gittus;;
  326 + archimport) : import;;
  327 + cat-file) : plumbing;;
  328 + check-attr) : plumbing;;
  329 + check-ref-format) : plumbing;;
  330 + commit-tree) : plumbing;;
  331 + cvsexportcommit) : export;;
  332 + cvsimport) : import;;
  333 + cvsserver) : daemon;;
  334 + daemon) : daemon;;
  335 + diff-files) : plumbing;;
  336 + diff-index) : plumbing;;
  337 + diff-tree) : plumbing;;
  338 + fast-import) : import;;
  339 + fsck-objects) : plumbing;;
  340 + fetch-pack) : plumbing;;
  341 + fmt-merge-msg) : plumbing;;
  342 + for-each-ref) : plumbing;;
  343 + hash-object) : plumbing;;
  344 + http-*) : transport;;
  345 + index-pack) : plumbing;;
  346 + init-db) : deprecated;;
  347 + local-fetch) : plumbing;;
  348 + mailinfo) : plumbing;;
  349 + mailsplit) : plumbing;;
  350 + merge-*) : plumbing;;
  351 + mktree) : plumbing;;
  352 + mktag) : plumbing;;
  353 + pack-objects) : plumbing;;
  354 + pack-redundant) : plumbing;;
  355 + pack-refs) : plumbing;;
  356 + parse-remote) : plumbing;;
  357 + patch-id) : plumbing;;
  358 + peek-remote) : plumbing;;
  359 + prune) : plumbing;;
  360 + prune-packed) : plumbing;;
  361 + quiltimport) : import;;
  362 + read-tree) : plumbing;;
  363 + receive-pack) : plumbing;;
  364 + reflog) : plumbing;;
  365 + repo-config) : deprecated;;
  366 + rerere) : plumbing;;
  367 + rev-list) : plumbing;;
  368 + rev-parse) : plumbing;;
  369 + runstatus) : plumbing;;
  370 + sh-setup) : internal;;
  371 + shell) : daemon;;
  372 + send-pack) : plumbing;;
  373 + show-index) : plumbing;;
  374 + ssh-*) : transport;;
  375 + stripspace) : plumbing;;
  376 + svn) : import export;;
  377 + symbolic-ref) : plumbing;;
  378 + tar-tree) : deprecated;;
  379 + unpack-file) : plumbing;;
  380 + unpack-objects) : plumbing;;
  381 + update-index) : plumbing;;
  382 + update-ref) : plumbing;;
  383 + update-server-info) : daemon;;
  384 + upload-archive) : plumbing;;
  385 + upload-pack) : plumbing;;
  386 + write-tree) : plumbing;;
  387 + verify-tag) : plumbing;;
  388 + *) echo $i;;
  389 + esac
  390 + done
  391 +}
  392 +__git_commandlist=
  393 +__git_commandlist="$(__git_commands 2>/dev/null)"
  394 +
  395 +__git_aliases ()
  396 +{
  397 + local i IFS=$'\n'
  398 + for i in $(git --git-dir="$(__gitdir)" config --list); do
  399 + case "$i" in
  400 + alias.*)
  401 + i="${i#alias.}"
  402 + echo "${i/=*/}"
  403 + ;;
  404 + esac
  405 + done
  406 +}
  407 +
  408 +__git_aliased_command ()
  409 +{
  410 + local word cmdline=$(git --git-dir="$(__gitdir)" \
  411 + config --get "alias.$1")
  412 + for word in $cmdline; do
  413 + if [ "${word##-*}" ]; then
  414 + echo $word
  415 + return
  416 + fi
  417 + done
  418 +}
  419 +
  420 +__git_whitespacelist="nowarn warn error error-all strip"
  421 +
  422 +_git_am ()
  423 +{
  424 + local cur="${COMP_WORDS[COMP_CWORD]}"
  425 + if [ -d .dotest ]; then
  426 + __gitcomp "--skip --resolved"
  427 + return
  428 + fi
  429 + case "$cur" in
  430 + --whitespace=*)
  431 + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  432 + return
  433 + ;;
  434 + --*)
  435 + __gitcomp "
  436 + --signoff --utf8 --binary --3way --interactive
  437 + --whitespace=
  438 + "
  439 + return
  440 + esac
  441 + COMPREPLY=()
  442 +}
  443 +
  444 +_git_apply ()
  445 +{
  446 + local cur="${COMP_WORDS[COMP_CWORD]}"
  447 + case "$cur" in
  448 + --whitespace=*)
  449 + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  450 + return
  451 + ;;
  452 + --*)
  453 + __gitcomp "
  454 + --stat --numstat --summary --check --index
  455 + --cached --index-info --reverse --reject --unidiff-zero
  456 + --apply --no-add --exclude=
  457 + --whitespace= --inaccurate-eof --verbose
  458 + "
  459 + return
  460 + esac
  461 + COMPREPLY=()
  462 +}
  463 +
  464 +_git_add ()
  465 +{
  466 + local cur="${COMP_WORDS[COMP_CWORD]}"
  467 + case "$cur" in
  468 + --*)
  469 + __gitcomp "--interactive --refresh"
  470 + return
  471 + esac
  472 + COMPREPLY=()
  473 +}
  474 +
  475 +_git_bisect ()
  476 +{
  477 + local i c=1 command
  478 + while [ $c -lt $COMP_CWORD ]; do
  479 + i="${COMP_WORDS[c]}"
  480 + case "$i" in
  481 + start|bad|good|reset|visualize|replay|log)
  482 + command="$i"
  483 + break
  484 + ;;
  485 + esac
  486 + c=$((++c))
  487 + done
  488 +
  489 + if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
  490 + __gitcomp "start bad good reset visualize replay log"
  491 + return
  492 + fi
  493 +
  494 + case "$command" in
  495 + bad|good|reset)
  496 + __gitcomp "$(__git_refs)"
  497 + ;;
  498 + *)
  499 + COMPREPLY=()
  500 + ;;
  501 + esac
  502 +}
  503 +
  504 +_git_branch ()
  505 +{
  506 + __gitcomp "$(__git_refs)"
  507 +}
  508 +
  509 +_git_bundle ()
  510 +{
  511 + local mycword="$COMP_CWORD"
  512 + case "${COMP_WORDS[0]}" in
  513 + git)
  514 + local cmd="${COMP_WORDS[2]}"
  515 + mycword="$((mycword-1))"
  516 + ;;
  517 + git-bundle*)
  518 + local cmd="${COMP_WORDS[1]}"
  519 + ;;
  520 + esac
  521 + case "$mycword" in
  522 + 1)
  523 + __gitcomp "create list-heads verify unbundle"
  524 + ;;
  525 + 2)
  526 + # looking for a file
  527 + ;;
  528 + *)
  529 + case "$cmd" in
  530 + create)
  531 + __git_complete_revlist
  532 + ;;
  533 + esac
  534 + ;;
  535 + esac
  536 +}
  537 +
  538 +_git_checkout ()
  539 +{
  540 + __gitcomp "$(__git_refs)"
  541 +}
  542 +
  543 +_git_cherry ()
  544 +{
  545 + __gitcomp "$(__git_refs)"
  546 +}
  547 +
  548 +_git_cherry_pick ()
  549 +{
  550 + local cur="${COMP_WORDS[COMP_CWORD]}"
  551 + case "$cur" in
  552 + --*)
  553 + __gitcomp "--edit --no-commit"
  554 + ;;
  555 + *)
  556 + __gitcomp "$(__git_refs)"
  557 + ;;
  558 + esac
  559 +}
  560 +
  561 +_git_commit ()
  562 +{
  563 + local cur="${COMP_WORDS[COMP_CWORD]}"
  564 + case "$cur" in
  565 + --*)
  566 + __gitcomp "
  567 + --all --author= --signoff --verify --no-verify
  568 + --edit --amend --include --only
  569 + "
  570 + return
  571 + esac
  572 + COMPREPLY=()
  573 +}
  574 +
  575 +_git_describe ()
  576 +{
  577 + __gitcomp "$(__git_refs)"
  578 +}
  579 +
  580 +_git_diff ()
  581 +{
  582 + local cur="${COMP_WORDS[COMP_CWORD]}"
  583 + case "$cur" in
  584 + --*)
  585 + __gitcomp "--cached --stat --numstat --shortstat --summary
  586 + --patch-with-stat --name-only --name-status --color
  587 + --no-color --color-words --no-renames --check
  588 + --full-index --binary --abbrev --diff-filter
  589 + --find-copies-harder --pickaxe-all --pickaxe-regex
  590 + --text --ignore-space-at-eol --ignore-space-change
  591 + --ignore-all-space --exit-code --quiet --ext-diff
  592 + --no-ext-diff"
  593 + return
  594 + ;;
  595 + esac
  596 + __git_complete_file
  597 +}
  598 +
  599 +_git_diff_tree ()
  600 +{
  601 + __gitcomp "$(__git_refs)"
  602 +}
  603 +
  604 +_git_fetch ()
  605 +{
  606 + local cur="${COMP_WORDS[COMP_CWORD]}"
  607 +
  608 + case "${COMP_WORDS[0]},$COMP_CWORD" in
  609 + git-fetch*,1)
  610 + __gitcomp "$(__git_remotes)"
  611 + ;;
  612 + git,2)
  613 + __gitcomp "$(__git_remotes)"
  614 + ;;
  615 + *)
  616 + case "$cur" in
  617 + *:*)
  618 + __gitcomp "$(__git_refs)" "" "${cur#*:}"
  619 + ;;
  620 + *)
  621 + local remote
  622 + case "${COMP_WORDS[0]}" in
  623 + git-fetch) remote="${COMP_WORDS[1]}" ;;
  624 + git) remote="${COMP_WORDS[2]}" ;;
  625 + esac
  626 + __gitcomp "$(__git_refs2 "$remote")"
  627 + ;;
  628 + esac
  629 + ;;
  630 + esac
  631 +}
  632 +
  633 +_git_format_patch ()
  634 +{
  635 + local cur="${COMP_WORDS[COMP_CWORD]}"
  636 + case "$cur" in
  637 + --*)
  638 + __gitcomp "
  639 + --stdout --attach --thread
  640 + --output-directory
  641 + --numbered --start-number
  642 + --numbered-files
  643 + --keep-subject
  644 + --signoff
  645 + --in-reply-to=
  646 + --full-index --binary
  647 + --not --all
  648 + "
  649 + return
  650 + ;;
  651 + esac
  652 + __git_complete_revlist
  653 +}
  654 +
  655 +_git_gc ()
  656 +{
  657 + local cur="${COMP_WORDS[COMP_CWORD]}"
  658 + case "$cur" in
  659 + --*)
  660 + __gitcomp "--prune --aggressive"
  661 + return
  662 + ;;
  663 + esac
  664 + COMPREPLY=()
  665 +}
  666 +
  667 +_git_ls_remote ()
  668 +{
  669 + __gitcomp "$(__git_remotes)"
  670 +}
  671 +
  672 +_git_ls_tree ()
  673 +{
  674 + __git_complete_file
  675 +}
  676 +
  677 +_git_log ()
  678 +{
  679 + local cur="${COMP_WORDS[COMP_CWORD]}"
  680 + case "$cur" in
  681 + --pretty=*)
  682 + __gitcomp "
  683 + oneline short medium full fuller email raw
  684 + " "" "${cur##--pretty=}"
  685 + return
  686 + ;;
  687 + --date=*)
  688 + __gitcomp "
  689 + relative iso8601 rfc2822 short local default
  690 + " "" "${cur##--date=}"
  691 + return
  692 + ;;
  693 + --*)
  694 + __gitcomp "
  695 + --max-count= --max-age= --since= --after=
  696 + --min-age= --before= --until=
  697 + --root --topo-order --date-order --reverse
  698 + --no-merges --follow
  699 + --abbrev-commit --abbrev=
  700 + --relative-date --date=
  701 + --author= --committer= --grep=
  702 + --all-match
  703 + --pretty= --name-status --name-only --raw
  704 + --not --all
  705 + --left-right --cherry-pick
  706 + "
  707 + return
  708 + ;;
  709 + esac
  710 + __git_complete_revlist
  711 +}
  712 +
  713 +_git_merge ()
  714 +{
  715 + local cur="${COMP_WORDS[COMP_CWORD]}"
  716 + case "${COMP_WORDS[COMP_CWORD-1]}" in
  717 + -s|--strategy)
  718 + __gitcomp "$(__git_merge_strategies)"
  719 + return
  720 + esac
  721 + case "$cur" in
  722 + --strategy=*)
  723 + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
  724 + return
  725 + ;;
  726 + --*)
  727 + __gitcomp "
  728 + --no-commit --no-summary --squash --strategy
  729 + "
  730 + return
  731 + esac
  732 + __gitcomp "$(__git_refs)"
  733 +}
  734 +
  735 +_git_merge_base ()
  736 +{
  737 + __gitcomp "$(__git_refs)"
  738 +}
  739 +
  740 +_git_name_rev ()
  741 +{
  742 + __gitcomp "--tags --all --stdin"
  743 +}
  744 +
  745 +_git_pull ()
  746 +{
  747 + local cur="${COMP_WORDS[COMP_CWORD]}"
  748 +
  749 + case "${COMP_WORDS[0]},$COMP_CWORD" in
  750 + git-pull*,1)
  751 + __gitcomp "$(__git_remotes)"
  752 + ;;
  753 + git,2)
  754 + __gitcomp "$(__git_remotes)"
  755 + ;;
  756 + *)
  757 + local remote
  758 + case "${COMP_WORDS[0]}" in
  759 + git-pull) remote="${COMP_WORDS[1]}" ;;
  760 + git) remote="${COMP_WORDS[2]}" ;;
  761 + esac
  762 + __gitcomp "$(__git_refs "$remote")"
  763 + ;;
  764 + esac
  765 +}
  766 +
  767 +_git_push ()
  768 +{
  769 + local cur="${COMP_WORDS[COMP_CWORD]}"
  770 +
  771 + case "${COMP_WORDS[0]},$COMP_CWORD" in
  772 + git-push*,1)
  773 + __gitcomp "$(__git_remotes)"
  774 + ;;
  775 + git,2)
  776 + __gitcomp "$(__git_remotes)"
  777 + ;;
  778 + *)
  779 + case "$cur" in
  780 + *:*)
  781 + local remote
  782 + case "${COMP_WORDS[0]}" in
  783 + git-push) remote="${COMP_WORDS[1]}" ;;
  784 + git) remote="${COMP_WORDS[2]}" ;;
  785 + esac
  786 + __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
  787 + ;;
  788 + +*)
  789 + __gitcomp "$(__git_refs)" + "${cur#+}"
  790 + ;;
  791 + *)
  792 + __gitcomp "$(__git_refs)"
  793 + ;;
  794 + esac
  795 + ;;
  796 + esac
  797 +}
  798 +
  799 +_git_rebase ()
  800 +{
  801 + local cur="${COMP_WORDS[COMP_CWORD]}"
  802 + if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
  803 + __gitcomp "--continue --skip --abort"
  804 + return
  805 + fi
  806 + case "${COMP_WORDS[COMP_CWORD-1]}" in
  807 + -s|--strategy)
  808 + __gitcomp "$(__git_merge_strategies)"
  809 + return
  810 + esac
  811 + case "$cur" in
  812 + --strategy=*)
  813 + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
  814 + return
  815 + ;;
  816 + --*)
  817 + __gitcomp "--onto --merge --strategy"
  818 + return
  819 + esac
  820 + __gitcomp "$(__git_refs)"
  821 +}
  822 +
  823 +_git_config ()
  824 +{
  825 + local cur="${COMP_WORDS[COMP_CWORD]}"
  826 + local prv="${COMP_WORDS[COMP_CWORD-1]}"
  827 + case "$prv" in
  828 + branch.*.remote)
  829 + __gitcomp "$(__git_remotes)"
  830 + return
  831 + ;;
  832 + branch.*.merge)
  833 + __gitcomp "$(__git_refs)"
  834 + return
  835 + ;;
  836 + remote.*.fetch)
  837 + local remote="${prv#remote.}"
  838 + remote="${remote%.fetch}"
  839 + __gitcomp "$(__git_refs_remotes "$remote")"
  840 + return
  841 + ;;
  842 + remote.*.push)
  843 + local remote="${prv#remote.}"
  844 + remote="${remote%.push}"
  845 + __gitcomp "$(git --git-dir="$(__gitdir)" \
  846 + for-each-ref --format='%(refname):%(refname)' \
  847 + refs/heads)"
  848 + return
  849 + ;;
  850 + pull.twohead|pull.octopus)
  851 + __gitcomp "$(__git_merge_strategies)"
  852 + return
  853 + ;;
  854 + color.branch|color.diff|color.status)
  855 + __gitcomp "always never auto"
  856 + return
  857 + ;;
  858 + color.*.*)
  859 + __gitcomp "
  860 + black red green yellow blue magenta cyan white
  861 + bold dim ul blink reverse
  862 + "
  863 + return