/bash_completion_lib/include/comp_install

http://github.com/brinkman83/bashrc · #! · 34 lines · 31 code · 3 blank · 0 comment · 0 complexity · fe4090e6d582d61ff91d0f9d9c2a1f77 MD5 · raw file

  1. # Install real completion
  2. # See also: _comp_install()
  3. # @param $* string (optional) Arguments to use for completion. Default is "-F _${BASH_ARGV[0]}"
  4. comp_install() {
  5. # Do not install when COMP_INSTALL equals 0
  6. if [ "${COMP_INSTALL:-1}" -ne 0 ]; then
  7. local comp=${BASH_ARGV[0]##*/} # ${..##*/}: strip up to and including last slash
  8. local dir="${BASH_ARGV[0]%/$comp}" # Extract dir from completion
  9. _comp_install $comp "$dir" "$*"
  10. fi
  11. } # comp_install()
  12. # Install real completion
  13. # NOTE: The default function of the original bash_completion is "_$command".
  14. # A less collision-prone default might be "_comp_$command", e.g.
  15. # `_comp_ssh' instead of `_ssh' -- FVu, Sat Apr 5 09:21:21 CEST 2008
  16. # @param $1 string comp
  17. # @param $2 string dir
  18. # @param $* string (optional) Arguments to use for completion. Default is "-F _${BASH_ARGV[0]}"
  19. _comp_install() {
  20. local comp=$1
  21. shift
  22. local dir="$1"
  23. shift
  24. # Don't install completion if 'comp_dir2args()' returns false
  25. if comp_dir2args "$dir"; then
  26. eval complete ${*:--F _$comp} $COMP_ARGS ${COMP_WORDS[0]}
  27. else
  28. complete -r $comp
  29. fi
  30. unset -v COMP_ARGS
  31. } # _comp_install()