PageRenderTime 115ms CodeModel.GetById 39ms app.highlight 0ms RepoModel.GetById 60ms app.codeStats 0ms

/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
 6
 7comp_include _expand
 8
 9
10_filedir()
11{
12	local IFS=$'\t\n' xspec #glob
13
14	_expand || return 0
15
16	#glob=$(set +o|grep noglob) # save glob setting.
17	#set -f		 # disable pathname expansion (globbing)
18
19	if [ "${1:-}" = -d ]; then
20		COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
21		#eval "$glob"    # restore glob setting.
22		return 0
23	fi
24
25	xspec=${1:+"!*.$1"}	# set only if glob passed in as $1
26	COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
27		    $( compgen -d -- "$cur" ) )
28	#eval "$glob"    # restore glob setting.
29} # _filedir()