[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-59-g2932491

Ville Skyttä ville.skytta at iki.fi
Sun Nov 20 18:07:10 UTC 2011


The following commit has been merged in the master branch:
commit 2932491a2c1ec611194d55a9390b708a32403b35
Author: Ville Skyttä <ville.skytta at iki.fi>
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



More information about the Bash-completion-commits mailing list