diff --git a/builtin_complete.cpp b/builtin_complete.cpp index f0eb6e1b1..691fad2b7 100644 --- a/builtin_complete.cpp +++ b/builtin_complete.cpp @@ -173,14 +173,16 @@ static void builtin_complete_add(const wcstring_list_t &cmd, static void builtin_complete_remove3(const wchar_t *cmd, int cmd_type, wchar_t short_opt, - const wcstring_list_t &long_opt) + const wcstring_list_t &long_opt, + int long_mode) { for (size_t i=0; ioptions.begin(); iter != this->options.end();) { complete_entry_opt_t &o = *iter; - if (short_opt==o.short_opt || long_opt == o.long_opt) + if ((short_opt && short_opt == o.short_opt) || + (long_opt && long_opt == o.long_opt && old_mode == o.old_mode)) { /* fwprintf( stderr, L"remove option -%lc --%ls\n", @@ -668,7 +669,8 @@ bool completion_entry_t::remove_option(wchar_t short_opt, const wchar_t *long_op void complete_remove(const wchar_t *cmd, bool cmd_is_path, wchar_t short_opt, - const wchar_t *long_opt) + const wchar_t *long_opt, + int old_mode) { CHECK(cmd,); scoped_lock lock(completion_lock); @@ -679,7 +681,7 @@ void complete_remove(const wchar_t *cmd, if (iter != completion_set.end()) { completion_entry_t *entry = *iter; - bool delete_it = entry->remove_option(short_opt, long_opt); + bool delete_it = entry->remove_option(short_opt, long_opt, old_mode); if (delete_it) { /* Delete this entry */ diff --git a/complete.h b/complete.h index 45eb2dc02..b5ad98c5e 100644 --- a/complete.h +++ b/complete.h @@ -207,7 +207,8 @@ void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authorit void complete_remove(const wchar_t *cmd, bool cmd_is_path, wchar_t short_opt, - const wchar_t *long_opt); + const wchar_t *long_opt, + int long_mode); /** Find all completions of the command cmd, insert them into out. diff --git a/tests/test.fish b/tests/test.fish index 7573b4001..2f2b8533b 100755 --- a/tests/test.fish +++ b/tests/test.fish @@ -61,14 +61,14 @@ for i in *.in else set res fail echo Output differs for file $i. Diff follows: - diff tmp.out $template_out + diff -u tmp.out $template_out end if diff tmp.err $template_err >/dev/null else set res fail echo Error output differs for file $i. Diff follows: - diff tmp.err $template_err + diff -u tmp.err $template_err end if test (cat tmp.status) = (cat $template_status) diff --git a/tests/test6.in b/tests/test6.in index e9b6e9b4d..93be594af 100755 --- a/tests/test6.in +++ b/tests/test6.in @@ -3,9 +3,43 @@ # We actually encountered some case that was effectively like this (Issue 2 in github) complete --command AAAA -l abcd --condition 'complete -c AAAA -l efgh' -complete -C'AAAA -' -complete -C'AAAA -' +echo "AAAA:" +complete -C'AAAA -' | sort +echo "AAAA:" +complete -C'AAAA -' | sort complete --command BBBB -l abcd --condition 'complete -e --command BBBB -l abcd' +echo "BBBB:" complete -C'BBBB -' +echo "BBBB:" complete -C'BBBB -' + +# Test that erasing completions works correctly +echo + +function sort + # GNU sort is really stupid, a non-C locale seems to make it assume --dictionary-order + # If I wanted --dictionary-order, I would have specified --dictionary-order! + env LC_ALL=C sort $argv +end + +complete -c CCCC -l bar +complete -c CCCC -l baz +complete -c CCCC -o bar +complete -c CCCC -o foo +complete -c CCCC -s a +complete -c CCCC -s b +echo "CCCC:" +complete -C'CCCC -' | sort +complete -c CCCC -l bar -e +echo "CCCC:" +complete -C'CCCC -' | sort +complete -c CCCC -o foo -e +echo "CCCC:" +complete -C'CCCC -' | sort +complete -c CCCC -s a -e +echo "CCCC:" +complete -C'CCCC -' | sort +complete -c CCCC -e +echo "CCCC:" +complete -C'CCCC -' | sort diff --git a/tests/test6.out b/tests/test6.out index 0b248b03b..d61d3c5f5 100644 --- a/tests/test6.out +++ b/tests/test6.out @@ -1,4 +1,32 @@ +AAAA: +--abcd +AAAA: --abcd --efgh +BBBB: --abcd ---abcd +BBBB: + +CCCC: +--bar +--baz +-a +-b +-bar +-foo +CCCC: +--baz +-a +-b +-bar +-foo +CCCC: +--baz +-a +-b +-bar +CCCC: +--baz +-b +-bar +CCCC: