1 | # #########################################################################
|
---|
2 | # This bash script adds tab-completion feature to django-admin.py and
|
---|
3 | # manage.py.
|
---|
4 | #
|
---|
5 | # Installation.
|
---|
6 | #
|
---|
7 | # Create a directory named .bash_completion in your home directory and move
|
---|
8 | # this file there. Now, if in your home exists a file called .profile use this
|
---|
9 | # one, otherwise use .bash_profile and add this line:
|
---|
10 | #
|
---|
11 | # source ~/.bash_completion/django
|
---|
12 | #
|
---|
13 | # Do the same in ~/.bashrc. Usually this shouldn't be necessary as
|
---|
14 | # .profile or .bash_profile take care to invoke .bashrc, if it exists, but
|
---|
15 | # different distributions handle this aspect differently.
|
---|
16 | #
|
---|
17 | # Settings will become effective since next login.
|
---|
18 | #
|
---|
19 | # Currently it is not supported models completion.
|
---|
20 | #
|
---|
21 | # Please, feedbacks or suggestions (expecially about models completion!) at
|
---|
22 | # paolo@php3.it or at paolo on freenode or at http://code.djangoproject.com/ticket/1240.
|
---|
23 | # Thanks.
|
---|
24 |
|
---|
25 | _django_completion()
|
---|
26 | {
|
---|
27 | local cur prev opts actions action_shell_opts
|
---|
28 | COMPREPLY=()
|
---|
29 | cur="${COMP_WORDS[COMP_CWORD]}"
|
---|
30 | prev="${COMP_WORDS[COMP_CWORD-1]}"
|
---|
31 |
|
---|
32 | # Standalone options.
|
---|
33 | opts="--help --settings --pythonpath"
|
---|
34 | # Actions.
|
---|
35 | actions="adminindex createcachetable createsuperuser \
|
---|
36 | init inspectdb install installperms runserver \
|
---|
37 | shell sql sqlall sqlclear sqlindexes sqlinitialdata \
|
---|
38 | sqlreset sqlsequencereset startapp startproject \
|
---|
39 | validate"
|
---|
40 | # Action's options.
|
---|
41 | action_shell_opts="--plain"
|
---|
42 |
|
---|
43 | if [[ # django-admin.py, ./manage, manage.py
|
---|
44 | ( ${COMP_CWORD} -eq 1 &&
|
---|
45 | ( ${COMP_WORDS[0]} == django-admin.py ||
|
---|
46 | ${COMP_WORDS[0]} == ./manage.py ||
|
---|
47 | ${COMP_WORDS[0]} == manage.py ) )
|
---|
48 | ||
|
---|
49 | # python manage.py, /some/path/python manage.py (if manage.py exists)
|
---|
50 | ( ${COMP_CWORD} -eq 2 &&
|
---|
51 | ( $( basename ${COMP_WORDS[0]} ) == python ) &&
|
---|
52 | ( $( basename ${COMP_WORDS[1]} ) == manage.py) &&
|
---|
53 | ( -r ${COMP_WORDS[1]} ) ) ]] ; then
|
---|
54 |
|
---|
55 | case ${cur} in
|
---|
56 | -*)
|
---|
57 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
---|
58 | return 0
|
---|
59 | ;;
|
---|
60 | *)
|
---|
61 | COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
|
---|
62 | return 0
|
---|
63 | ;;
|
---|
64 | esac
|
---|
65 | else
|
---|
66 | case ${prev} in
|
---|
67 | adminindex|install|installperms| \
|
---|
68 | sql|sqlall|sqlclear|sqlindexes| \
|
---|
69 | sqlinitialdata|sqlreset|sqlsequencereset)
|
---|
70 | # Actually modelmodules completion is not supported.
|
---|
71 | # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
|
---|
72 | COMPREPLY=()
|
---|
73 | return 0
|
---|
74 | ;;
|
---|
75 |
|
---|
76 | createcachetable|createsuperuser|init| \
|
---|
77 | inspectdb|runserver|startapp|startproject| \
|
---|
78 | validate)
|
---|
79 | COMPREPLY=()
|
---|
80 | return 0
|
---|
81 | ;;
|
---|
82 | shell)
|
---|
83 | COMPREPLY=( $(compgen -W "$action_shell_opts" -- ${cur}) )
|
---|
84 | return 0
|
---|
85 | ;;
|
---|
86 | *)
|
---|
87 | #COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
|
---|
88 | COMPREPLY=()
|
---|
89 | return 0
|
---|
90 | ;;
|
---|
91 | esac
|
---|
92 | fi
|
---|
93 | }
|
---|
94 |
|
---|
95 | complete -F _django_completion django-admin.py manage.py
|
---|
96 | complete -F _django_completion -o default python
|
---|