diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-20 20:01:13 +0200 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-20 20:01:13 +0200 |
commit | 2932491a2c1ec611194d55a9390b708a32403b35 (patch) | |
tree | fd92805871f0ecaafac14c3ceafdff8748b127b9 /completions | |
parent | a8218ee1c9337fc8e37431d310b5a7e95d9fbfe5 (diff) | |
download | bash-completion-2932491a2c1ec611194d55a9390b708a32403b35.tar.gz |
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.
Diffstat (limited to 'completions')
-rw-r--r-- | completions/dict | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/completions/dict b/completions/dict index 3caedf76..a2ecd9b1 100644 --- a/completions/dict +++ b/completions/dict @@ -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 |