Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

No way to properly complete specific set of files



Hi,

I have an array, let's say:

  files=('Documents' 'Downloads' 'Downloads/test' 'Videos')

And I want to complete those files, with all the niceties that _file has.

I could do the same as _git and others do:

  _multi_parts -f -- / files

But that doesn't work; the files are not detected. And it doesn't
complete the same way.

Or I could use _path_files, as somebody suggested on the list, but
that doesn't limit the list of files.

It would have been very easy to tell _path_files which files to
complete, but no, I have to manually implement the completion myself:

---
#compdef foobar

_foobar_1 ()
{
	_multi_parts -f -- / $1
}

_foobar_2 ()
{
	_path_files
}

_foobar_3 ()
{
	local -a list
	local pfx="" cur="${words[CURRENT]}" file

	case "$cur" in
	?*/*)
		pfx="${cur%/*}"
		cur="${cur##*/}"
		pfx="${pfx}/"
		;;
	esac

	for file in ${(P)1}; do
		case "$file" in
		${pfx}*)
			file="${file##$pfx}"
			;;
		*)
			continue
			;;
		esac
		case "$file" in
		?*/*)
			list+="${file%%/*}"
			;;
		*)
			list+="${file}"
			;;
		esac
	done

	compadd -Q -p "${pfx-}" -f -a list
}

_foobar ()
{
	local -a files
	files=('Documents' 'Downloads' 'Downloads/test' 'Videos')
	_foobar_3 files
	return 0
}

_foobar
---

Am I missing something?

-- 
Felipe Contreras



Messages sorted by: Reverse Date, Date, Thread, Author