Skip to content

Commit

Permalink
completion: Cap max-errors at 7 to avoid hanging (sorin-ionescu#953)
Browse files Browse the repository at this point in the history
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 sorin-ionescu#946.
  • Loading branch information
catharsis authored and eduardolundgren committed Jul 8, 2017
1 parent 44fce9d commit f8503db
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/completion/init.zsh
Expand Up @@ -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))'
Expand Down

0 comments on commit f8503db

Please sign in to comment.