/bash_completion_lib/include/_filedir
http://github.com/brinkman83/bashrc · #! · 29 lines · 21 code · 8 blank · 0 comment · 0 complexity · cbf0998dae257788f6f712a122056f89 MD5 · raw file
- # This function performs file and directory completion. It's better than
- # simply using 'compgen -f', because it honours spaces in filenames.
- # If passed -d, it completes only on directories. If passed anything else,
- # it's assumed to be a file glob to complete on.
- comp_include _expand
- _filedir()
- {
- local IFS=$'\t\n' xspec #glob
- _expand || return 0
- #glob=$(set +o|grep noglob) # save glob setting.
- #set -f # disable pathname expansion (globbing)
- if [ "${1:-}" = -d ]; then
- COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
- #eval "$glob" # restore glob setting.
- return 0
- fi
- xspec=${1:+"!*.$1"} # set only if glob passed in as $1
- COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
- $( compgen -d -- "$cur" ) )
- #eval "$glob" # restore glob setting.
- } # _filedir()