dict: Speed up word completion with common use cases and large word lists.
/usr/share/dict/words has 479829 entries on my box which is too much for practical compgen -W usage, narrow it down with grep in common use cases.
This commit is contained in:
parent
a8218ee1c9
commit
2932491a2c
@ -54,8 +54,17 @@ _dict()
|
||||
esac
|
||||
|
||||
local dictfile=/usr/share/dict/words
|
||||
[[ -r $dictfile ]] && \
|
||||
COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
|
||||
if [[ -r $dictfile ]]; then
|
||||
# Dictfile may be too large for practical compgen -W usage, so narrow
|
||||
# it down with grep if $cur looks like something that's safe to embed
|
||||
# in a pattern instead.
|
||||
if [[ $cur == +([-A-Za-z0-9/.]) ]]; then
|
||||
COMPREPLY=( $( compgen -W \
|
||||
'$( command grep "^${cur//./\\.}" $dictfile )' -- "$cur" ) )
|
||||
else
|
||||
COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
|
||||
fi
|
||||
fi
|
||||
} &&
|
||||
complete -F _dict -o default dict rdict
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user