/bash_completion_lib/include/_filedir

http://github.com/brinkman83/bashrc · #! · 29 lines · 21 code · 8 blank · 0 comment · 0 complexity · cbf0998dae257788f6f712a122056f89 MD5 · raw file

  1. # This function performs file and directory completion. It's better than
  2. # simply using 'compgen -f', because it honours spaces in filenames.
  3. # If passed -d, it completes only on directories. If passed anything else,
  4. # it's assumed to be a file glob to complete on.
  5. comp_include _expand
  6. _filedir()
  7. {
  8. local IFS=$'\t\n' xspec #glob
  9. _expand || return 0
  10. #glob=$(set +o|grep noglob) # save glob setting.
  11. #set -f # disable pathname expansion (globbing)
  12. if [ "${1:-}" = -d ]; then
  13. COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
  14. #eval "$glob" # restore glob setting.
  15. return 0
  16. fi
  17. xspec=${1:+"!*.$1"} # set only if glob passed in as $1
  18. COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
  19. $( compgen -d -- "$cur" ) )
  20. #eval "$glob" # restore glob setting.
  21. } # _filedir()