git_completion.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # This adds completion to bash shells for git commands. It is
  5. # meant for developers and not needed for inclusion by any automated
  6. # processes that will, of course, specify the full command, not rely
  7. # on or benefit from tab-completion.
  8. #
  9. # Requires:
  10. # Installed git bash completion.
  11. #
  12. # Usage:
  13. # Add this to your .bashrc:
  14. #
  15. # # The next lines enable bash completion for git commands from
  16. # # depot_tools.
  17. # if [ -f "$HOME/bin/depot_tools/git_completion.sh" ]; then
  18. # . "$HOME/bin/depot_tools/git_completion.sh"
  19. # fi
  20. _git_new_branch ()
  21. {
  22. case "$cur" in
  23. -*)
  24. __gitcomp_nl_append "--upstream_current"
  25. __gitcomp_nl_append "--upstream"
  26. __gitcomp_nl_append "--lkgr"
  27. __gitcomp_nl_append "--inject_current"
  28. ;;
  29. *)
  30. case "$prev,$cur" in
  31. --upstream,o*)
  32. # By default (only local branch heads are shown after --upstream, see
  33. # the case below. If, however, the user types "--upstream o", also
  34. # remote branches (origin/*) are shown.
  35. __git_complete_refs --cur="$cur"
  36. ;;
  37. --upstream,*)
  38. __gitcomp_nl "$(__git_heads '' $cur)"
  39. ;;
  40. esac
  41. esac
  42. }
  43. _git_reparent_branch ()
  44. {
  45. case "$cur" in
  46. -*)
  47. __gitcomp_nl_append "--lkgr"
  48. __gitcomp_nl_append "--root"
  49. ;;
  50. o*)
  51. # By default (only local branch heads are shown after --upstream, see the
  52. # case below. If, however, the user types "--upstream o", also remote
  53. # branches (origin/*) are shown.
  54. __git_complete_refs --cur="$cur"
  55. ;;
  56. *)
  57. __gitcomp_nl "$(__git_heads '' $cur)"
  58. ;;
  59. esac
  60. }