git_cl_completion.sh 962 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (c) 2016 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 cl 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. # Put something like the following in your .bashrc:
  14. # . $PATH_TO_DEPOT_TOOLS/git cl_completion.sh
  15. #
  16. # Parses commands from git cl -h.
  17. __git_cl_commands () {
  18. git cl -h 2> /dev/null | sed -n 's/^\s*\x1b\[32m\(.*\)\x1b\[39m.*$/\1/p'
  19. }
  20. # Caches variables in __git_cl_all_commands.
  21. __git_cl_compute_all_commands () {
  22. test -n "$__git_cl_all_commands" ||
  23. __git_cl_all_commands="$(__git_cl_commands)"
  24. }
  25. _git_cl () {
  26. __git_cl_compute_all_commands
  27. __gitcomp_nl "$(__git_cl_commands)"
  28. }