From 5c0e68f75fe9d45ef352b29976265780d11763b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=C3=B6fgren?= Date: Thu, 13 Apr 2017 11:47:51 +0200 Subject: [PATCH] completion: Cap max-errors at 7 to avoid hanging (#953) 7 is pretty arbitrarily chosen, but seems like a reasonable tradeoff, at least the completion no longer shows symptoms of exponential time-growth when trying to complete something completely wrong. This fixes #946. --- modules/completion/init.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh index 023a90e..620a9b3 100644 --- a/modules/completion/init.zsh +++ b/modules/completion/init.zsh @@ -66,8 +66,9 @@ zstyle ':completion:*' completer _complete _match _approximate zstyle ':completion:*:match:*' original only zstyle ':completion:*:approximate:*' max-errors 1 numeric -# Increase the number of errors based on the length of the typed word. -zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' +# Increase the number of errors based on the length of the typed word. But make +# sure to cap (at 7) the max-errors to avoid hanging. +zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)' # Don't complete unavailable commands. zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'