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

Re: Completion function for bitkeeper?

I completely neglected to add the _sccsfiles function to the mail, and
now that I'm being asked about it again, I figure I should just send it
to the list.  :)

If someone can explain me out of my confusion in the first big comment,
that'd be really nice, but what I have appears to work.

#autoload +X

# %W% %E%

_sccsfiles () {
	local i=1 pfiles pdirs sfile="SCCS/s."

	# If _sccsfiles is called from one of the _sccs_* functions, then
	# it'll have some compadd options added after the first word, so
	# the positional parameters are not all "ours".
	# One option is to precede the call to _sccsfiles in the optspec's
	# action with a space, which prevents these extra parameters from
	# being passed in.  Ugh.  See the documentation for _arguments in
	# zshcompsys(1), where it talks about action starting with a space.
	# Instead, remove the first few arguments if they match $expl.  Why
	# they're passed in both places I don't know (and this may be a
	# bug).

	while [[ -n "$1" && "$1" == "$expl[i]" ]]; do

	[[ "$1" == "-e" ]] && sfile="SCCS/p."

	compset -P "*/"

	# Add matching files
	pfiles=( ${IPREFIX}${sfile}${PREFIX}*(.N) )
	pfiles=( ${pfiles/${IPREFIX}${sfile}} )
	compadd -af pfiles

	# Add matching directories
	# This should be made more efficient to only descend as far as
	# necessary in each directory to find an s. file.
	if [[ -z ${PREFIX} ]]; then
		pdirs=( ${IPREFIX}**/${sfile}*(.N) )
		pdirs=( ${IPREFIX}${PREFIX}*/**/${sfile}*(.N) )

	# Remove IPREFIX, then only take first-level directory
	pdirs=( ${^${pdirs/${IPREFIX}}%%/*} )
	# Remove SCCS directories
	pdirs=( ${pdirs:#SCCS} )

	compadd -aq -S / pdirs

	# Explicitly return success as the above may have failed.
	return 0

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