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

[PATCH 0/5] bashcompinit: several fixes



Hi,

While trying to resolve the issue I reported before[1], I stumbled upon many
problems in the current code, here are a bunch of patches that should address
all the issues I found.

I used the following test script to verify my changes, and now all the tests
pass, just like in bash :)

---
#!/bin/sh

if [[ -n ${ZSH_VERSION-} ]]; then
    autoload -U +X bashcompinit && bashcompinit
fi

cwords[1]='first '
cwords[2]='second and space '
cwords[3]='third\\ quoted\\ space '
cwords[4]='fourth\\ quoted\\ space plus'

unescape()
{
	printf "%b" "$1"
}

prepare()
{
	local IFS=$'\n'
	echo "== prepare =="
	mkdir -p tmp
	for e in "${cwords[@]}"
	do
		u=$(unescape "$e")
		touch "tmp/$u"
	done
}

compare()
{
	test "$1" != "$2" && echo -e "error: '$1' != '$2'" && return -1 || return 0
}

_foo()
{
	local IFS=$'\n'
	COMPREPLY=( $(compgen -W "${cwords[*]}" -- "$2") )
}

test_3()
{
	local fail
	echo "== test 3 =="
	pushd "tmp"
	for e in "${cwords[@]}"
	do
		compare "$(compgen -o filenames -f -- ${e:0:2})" "$(unescape "$e")" || fail=true
	done
	popd
	test $fail || echo "OK"
}

test_2()
{
	local fail
	echo "== test 2 =="
	for e in "${cwords[@]}"
	do
		compare "$(compgen -F _foo -- ${e:0:2})" "$(unescape "$e")" || fail=true
	done
	test $fail || echo "OK"
}

test_1()
{
	local IFS=$'\n'
	local fail
	echo "== test 1 =="
	for e in "${cwords[@]}"
	do
		compare "$(compgen -W "${cwords[*]}" -- ${e:0:2})" "$(unescape "$e")" || fail=true
	done
	test $fail || echo "OK"
}

prepare
test_1
test_2
test_3
---

[1] http://article.gmane.org/gmane.comp.shells.zsh.devel/24279

Felipe Contreras (5):
  bashcompinit: remove _compgen_opt_words
  bashcompinit: fix COMP_POINT
  bashcompinit: fix quoting code
  bashcompinit: simplify result matching code
  bashcompinit: improve compgen -F argument passing

 Completion/bashcompinit |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

-- 
1.7.8.3



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