summaryrefslogtreecommitdiff
path: root/Completion/Base/Completer/_approximate
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2025-04-30 02:07:56 -0700
committerJoe Rayhawk <jrayhawk@fairlystable.org>2025-04-30 02:07:56 -0700
commit26e09889646be3ea65b4a3dfeda26213e4bb6a27 (patch)
tree4f3c73a9416bf47ad7e125383d23cf42879e38d7 /Completion/Base/Completer/_approximate
parent841bce705a58b04220b1f257abcc00ae71cbdbdc (diff)
parent001cba48ce3b964cf01fb3e2af54b20eacbc9bf5 (diff)
downloadzsh-26e09889646be3ea65b4a3dfeda26213e4bb6a27.tar.gz
zsh-26e09889646be3ea65b4a3dfeda26213e4bb6a27.zip
Merge branch 'upstream' into debian
Diffstat (limited to 'Completion/Base/Completer/_approximate')
-rw-r--r--Completion/Base/Completer/_approximate48
1 files changed, 22 insertions, 26 deletions
diff --git a/Completion/Base/Completer/_approximate b/Completion/Base/Completer/_approximate
index dcd8b2776..96860b5a7 100644
--- a/Completion/Base/Completer/_approximate
+++ b/Completion/Base/Completer/_approximate
@@ -12,7 +12,6 @@
local _comp_correct _correct_expl _correct_group comax cfgacc match
local oldcontext="${curcontext}" opm="$compstate[pattern_match]"
-local dounfunction
integer ret=1
if [[ "$1" = -a* ]]; then
@@ -44,34 +43,31 @@ fi
_tags corrections original
-# Otherwise temporarily define a function to use instead of
-# the builtin that adds matches. This is used to be able
-# to stick the `(#a...)' in the right place (after an
-# ignored prefix).
+# Otherwise temporarily define a function to use instead of the builtin that
+# adds matches. This is used to be able to stick the `(#a...)' in the right
+# place (after an ignored prefix).
#
-# Current shell structure for use with "always", to make sure
-# we unfunction the compadd.
+# Current shell structure for use with "always", to make sure we unfunction our
+# compadd and restore any compadd function defined previously.
{
-if (( ! $+functions[compadd] )); then
- dounfunction=1
- compadd() {
- local ppre="$argv[(I)-p]"
-
- [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 &&
- "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
-
- if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
- PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
- else
- PREFIX="(#a${_comp_correct})$PREFIX"
- fi
+_shadow -s _approximate compadd
+compadd() {
+ local ppre="$argv[(I)-p]"
- (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) &&
- _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]}
+ [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 &&
+ "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
- builtin compadd "$_correct_expl[@]" "$@"
- }
-fi
+ if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
+ PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
+ else
+ PREFIX="(#a${_comp_correct})$PREFIX"
+ fi
+
+ (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) &&
+ _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]}
+
+ compadd@_approximate "$_correct_expl[@]" "$@"
+}
_comp_correct=1
@@ -115,7 +111,7 @@ while [[ _comp_correct -le comax ]]; do
done
} always {
- [[ -n $dounfunction ]] && (( $+functions[compadd] )) && unfunction compadd
+ _unshadow
}
(( ret == 0 )) && return 0