/bash_completion_lib/include/comp_include

http://github.com/brinkman83/bashrc · #! · 20 lines · 18 code · 2 blank · 0 comment · 0 complexity · cef8852bdfd13234151fc684c895e4e6 MD5 · raw file

  1. # Include completion files - if not already loaded. Each directory in $COMP_PATH is
  2. # examined for "./include/file"
  3. # @param $* string Files to include
  4. # NOTE: Each file must have at least one function with the same name as the
  5. # filename. This way `comp_include' can detect if a file already has been
  6. # included. For example, file `cd' must have a function `cd()'.
  7. comp_include() {
  8. local s
  9. for s; do
  10. if ! declare -F "$s" &> /dev/null; then
  11. # Convert colon (:) separated string `COMP_PATH' to array `aPaths'
  12. local dir OLDIFS=$IFS; IFS=:; local -a aPaths=($COMP_PATH); IFS=$OLDIFS
  13. for dir in "${aPaths[@]}"; do
  14. [ -r "$dir/include/$s" ] && . "$dir/include/$s" && break
  15. done
  16. fi
  17. done
  18. } # comp_include()