Skip to content

Commit

Permalink
completions-getter: Override compopt only temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
3v1n0 committed Sep 8, 2022
1 parent 5c093f9 commit da560de
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bash-completions-getter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.txt)
#

compopt() {
overridden_compopt() {
# TODO implement default case addition and removal
[ -z "$_COMP_OPTIONS" ] &&
_COMP_OPTIONS=()
Expand Down Expand Up @@ -209,6 +209,11 @@ get_completions() {

_COMP_OPTIONS=()

function compopt() {
overridden_compopt "$@"
return $?
}

COMP_LINE=${ZSH_BUFFER}
COMP_POINT=${ZSH_CURSOR:-${#COMP_LINE}}
COMP_WORDBREAKS=${ZSH_WORDBREAKS}
Expand Down Expand Up @@ -259,6 +264,7 @@ get_completions() {
completion="$COMPLETE_CALL"
_COMP_OPTIONS+=("${COMPLETE_OPTIONS[@]}")
else
unset -f compopt
return 1;
fi

Expand All @@ -270,9 +276,12 @@ get_completions() {
echo -n "WORDS: " >&2; printf "'%s'," "${COMPLETE_WORDS[@]}" >&2; echo >&2
fi

unset -f compopt

if [ ${#COMPLETE_WORDS[@]} -gt 0 ] ||
[ ${#COMPLETE_OPTIONS[@]} -gt 0 ] ||
[ ${#COMPLETE_ACTIONS[@]} -gt 0 ]; then
unset -f compopt
echo "${_COMP_OPTIONS[@]}"
echo "${COMPLETE_ACTIONS[@]}"
printf "%s\n" "${COMPLETE_WORDS[@]}"
Expand Down Expand Up @@ -309,6 +318,7 @@ get_completions() {
export COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_WORDBREAKS
mapfile -t COMPREPLY < <("${cmd[@]}" 2>"$errorout")
elif ! "${cmd[@]}" 2>"$errorout"; then
unset -f compopt
return 1
fi

Expand All @@ -321,6 +331,8 @@ get_completions() {
echo -n "REPLY: " >&2; printf "'%s'," "${COMPREPLY[@]}" >&2; echo >&2
fi

unset -f compopt

# print options, followed by completions to stdout
echo "${_COMP_OPTIONS[@]}"
echo "${COMPLETE_ACTIONS[@]}"
Expand Down

0 comments on commit da560de

Please sign in to comment.