55# License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.txt)
66#
77
8- compopt () {
8+ overridden_compopt () {
99 # TODO implement default case addition and removal
1010 [ -z " $_COMP_OPTIONS " ] &&
1111 _COMP_OPTIONS=()
@@ -209,6 +209,11 @@ get_completions() {
209209
210210 _COMP_OPTIONS=()
211211
212+ function compopt() {
213+ overridden_compopt " $@ "
214+ return $?
215+ }
216+
212217 COMP_LINE=${ZSH_BUFFER}
213218 COMP_POINT=${ZSH_CURSOR:- ${# COMP_LINE} }
214219 COMP_WORDBREAKS=${ZSH_WORDBREAKS}
@@ -259,6 +264,7 @@ get_completions() {
259264 completion=" $COMPLETE_CALL "
260265 _COMP_OPTIONS+=(" ${COMPLETE_OPTIONS[@]} " )
261266 else
267+ unset -f compopt
262268 return 1;
263269 fi
264270
@@ -270,9 +276,12 @@ get_completions() {
270276 echo -n " WORDS: " >&2 ; printf " '%s'," " ${COMPLETE_WORDS[@]} " >&2 ; echo >&2
271277 fi
272278
279+ unset -f compopt
280+
273281 if [ ${# COMPLETE_WORDS[@]} -gt 0 ] ||
274282 [ ${# COMPLETE_OPTIONS[@]} -gt 0 ] ||
275283 [ ${# COMPLETE_ACTIONS[@]} -gt 0 ]; then
284+ unset -f compopt
276285 echo " ${_COMP_OPTIONS[@]} "
277286 echo " ${COMPLETE_ACTIONS[@]} "
278287 printf " %s\n" " ${COMPLETE_WORDS[@]} "
@@ -309,6 +318,7 @@ get_completions() {
309318 export COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_WORDBREAKS
310319 mapfile -t COMPREPLY < <( " ${cmd[@]} " 2> " $errorout " )
311320 elif ! " ${cmd[@]} " 2> " $errorout " ; then
321+ unset -f compopt
312322 return 1
313323 fi
314324
@@ -321,6 +331,8 @@ get_completions() {
321331 echo -n " REPLY: " >&2 ; printf " '%s'," " ${COMPREPLY[@]} " >&2 ; echo >&2
322332 fi
323333
334+ unset -f compopt
335+
324336 # print options, followed by completions to stdout
325337 echo " ${_COMP_OPTIONS[@]} "
326338 echo " ${COMPLETE_ACTIONS[@]} "
0 commit comments