The following commit has been merged in the master branch:
commit 2932491a2c1ec611194d55a9390b708a32403b35
Author: Ville Skyttä <[email protected]>
Date:   Sun Nov 20 20:01:13 2011 +0200

    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.

diff --git a/completions/dict b/completions/dict
index 3caedf7..a2ecd9b 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
 

-- 
bash-completion

_______________________________________________
Bash-completion-commits mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-commits

Reply via email to