Code

Ticket #1240: appname-completion.diff

File appname-completion.diff, 1.5 KB (added by scott@…, 8 years ago)

[patch] appname completion

Line 
133a34,48
2> # the script below requires that you be in the same directory as
3> # your settings.py, much like manage.py does
4>
5> PYTHON_FIND_APPS=$( cat <<'EOF'
6> try:
7>     from os.path import dirname,basename,realpath; import settings,sys,os
8>     os.environ['DJANGO_SETTINGS_MODULE']='%s.settings' % \
9>         basename(dirname(realpath(settings.__file__)))
10>     from django.db.models import get_apps
11>     print ' '.join([a.__name__.split('.')[-2] for a in get_apps()])
12> except:
13>     print ''
14> EOF
15> )
16>
1752a68
18>
1976a93
20>         
2177a95,100
22>         if [[ # last word was 'python' return empty so filename completion can take place
23>             ( $( basename ${prev} ) == python ) ]] ; then
24>             COMPREPLY=()
25>             return 0
26>         fi
27>             
2882,85c105
29<             # App completion isn't yet implemented, but here's where that
30<             # would go.
31<             # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
32<             COMPREPLY=()
33---
34>             COMPREPLY=( $(compgen -W "`echo \"$PYTHON_FIND_APPS\" | python -`" -- ${cur})  )
35111,112c131
36<                 #COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
37<                 COMPREPLY=()
38---
39>                 COMPREPLY=( $(compgen -W "`echo \"$PYTHON_FIND_APPS\" | python -`" -- ${cur}) )
40119c138,140
41< complete -F _django_completion django-admin.py manage.py
42---
43> # -o default resorts to filename completion if we don't return any words
44>
45> complete -F _django_completion -o default python django-admin.py manage.py