Dominic Battre | 272e6ab | 2023-09-15 06:27:53 +0000 | [diff] [blame^] | 1 | # Copyright (c) 2023 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | |
| 6 | # This adds completion to bash shells for git commands. It is |
| 7 | # meant for developers and not needed for inclusion by any automated |
| 8 | # processes that will, of course, specify the full command, not rely |
| 9 | # on or benefit from tab-completion. |
| 10 | # |
| 11 | # Requires: |
| 12 | # Installed git bash completion. |
| 13 | # |
| 14 | # Usage: |
| 15 | # Add this to your .bashrc: |
| 16 | # |
| 17 | # # The next lines enable bash completion for git commands from |
| 18 | # # depot_tools. |
| 19 | # if [ -f "$HOME/bin/depot_tools/git_completion.sh" ]; then |
| 20 | # . "$HOME/bin/depot_tools/git_completion.sh" |
| 21 | # fi |
| 22 | |
| 23 | |
| 24 | _git_new_branch () |
| 25 | { |
| 26 | case "$cur" in |
| 27 | -*) |
| 28 | __gitcomp_nl_append "--upstream_current" |
| 29 | __gitcomp_nl_append "--upstream" |
| 30 | __gitcomp_nl_append "--lkgr" |
| 31 | __gitcomp_nl_append "--inject_current" |
| 32 | ;; |
| 33 | *) |
| 34 | case "$prev,$cur" in |
| 35 | --upstream,o*) |
| 36 | # By default (only local branch heads are shown after --upstream, see |
| 37 | # the case below. If, however, the user types "--upstream o", also |
| 38 | # remote branches (origin/*) are shown. |
| 39 | __git_complete_refs --cur="$cur" |
| 40 | ;; |
| 41 | --upstream,*) |
| 42 | __gitcomp_nl "$(__git_heads '' $cur)" |
| 43 | ;; |
| 44 | esac |
| 45 | esac |
| 46 | } |
| 47 | |
| 48 | _git_reparent_branch () |
| 49 | { |
| 50 | case "$cur" in |
| 51 | -*) |
| 52 | __gitcomp_nl_append "--lkgr" |
| 53 | __gitcomp_nl_append "--root" |
| 54 | ;; |
| 55 | o*) |
| 56 | # By default (only local branch heads are shown after --upstream, see the |
| 57 | # case below. If, however, the user types "--upstream o", also remote |
| 58 | # branches (origin/*) are shown. |
| 59 | __git_complete_refs --cur="$cur" |
| 60 | ;; |
| 61 | *) |
| 62 | __gitcomp_nl "$(__git_heads '' $cur)" |
| 63 | ;; |
| 64 | esac |
| 65 | } |