Browse Source

Fixed #1240: added better support for different names for "python" to django_bash_completion. Thanks, paolo.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Jacob Kaplan-Moss 18 years ago
parent
commit
0e683f6da4
1 changed files with 23 additions and 1 deletions
  1. 23 1
      extras/django_bash_completion

+ 23 - 1
extras/django_bash_completion

@@ -31,6 +31,9 @@
 #
 # To uninstall, just remove the line from your .bash_profile and .bashrc.
 
+# Enable extended pattern matching operators.
+shopt -s extglob
+
 _django_completion()
 {
     local cur prev opts actions action_shell_opts action_runfcgi_opts
@@ -58,8 +61,13 @@ _django_completion()
           ||
           # python manage.py, /some/path/python manage.py (if manage.py exists)
           ( ${COMP_CWORD} -eq 2 &&
-            ( $( basename ${COMP_WORDS[0]} ) == python ) &&
+            ( $( basename ${COMP_WORDS[0]} ) == python?([1-9]\.[0-9]) ) &&
             ( $( basename ${COMP_WORDS[1]} ) == manage.py) &&
+            ( -r ${COMP_WORDS[1]} ) ) 
+          ||
+          ( ${COMP_CWORD} -eq 2 &&
+            ( $( basename ${COMP_WORDS[0]} ) == python?([1-9]\.[0-9]) ) &&
+            ( $( basename ${COMP_WORDS[1]} ) == django-admin.py) &&
             ( -r ${COMP_WORDS[1]} ) ) ]] ; then
 
         case ${cur} in
@@ -135,3 +143,17 @@ _django_completion()
 }
 
 complete -F _django_completion django-admin.py manage.py
+
+# Support for multiple interpreters.
+unset pythons
+if command -v whereis &>/dev/null; then
+    python_interpreters=$(whereis -b python | cut -d " " -f 2-) 
+    for python in $python_interpreters; do
+        pythons="${pythons} $(basename $python)"
+    done
+    pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
+else
+    pythons=python    
+fi
+
+complete -F _django_completion -o default $pythons