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

Quoting with compadd



Hi there, I'm trying to build a completion function for the mighty zsh
to provide filename completion for the 'j' script
(http://github.com/rupa/j/tree/master). It seems whenever I use
compadd, newlines are incorrectly quoted.

This awful attempt is the best I could come up with so far (assuming
'compdef j_complete j')
j_complete() {
	local -a dirs
	dirs=$(grep -o -e ${words[CURRENT]}'[^|]*' < ~/.j)
	compadd $dirs
}

However, the newlines in $dirs are quoted by compadd (as are the
spaces). I'm assuming that compadd would prefer spaces in the
filenames be quoted and newlines turned into spaces. I've tried piping
into sed to manually quote spaces, then into tr to turn newlines into
spaces, but compadd then quotes the lot.

The completion needs to scan the file ~/.j for directories containing
the completion word. The file has the format <dir>|<count>|<time>
(notice non-greedy matching in egrep because of the second '|').
Ideally completion should only be offered where the completion word
matches the beginning of a path or part of a path string that follows
'/'.



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