Django

Code

root/django/branches/magic-removal/extras/django_bash_completion

Revision 2742, 3.3 kB (checked in by adrian, 3 years ago)

magic-removal: Fixed #1240 -- Added Django bash completion script in new extras/ directory. Thanks, paolo

Line 
1 # #########################################################################
2 # This bash script adds tab-completion feature to django-admin.py and
3 # manage.py.
4 #
5 # Testing it out without installing
6 # =================================
7 #
8 # To test out the completion without "installing" this, just run this file
9 # directly, like so:
10 #
11 #     . ~/path/to/django_bash_completion
12 #
13 # Note: There's a dot ('.') at the beginning of that command.
14 #
15 # After you do that, tab completion will immediately be made available in your
16 # current Bash shell. But it won't be available next time you log in.
17 #
18 # Installing
19 # ==========
20 #
21 # To install this, point to this file from your .bash_profile, like so:
22 #
23 #     . ~/path/to/django_bash_completion
24 #
25 # Do the same in your .bashrc if .bashrc doesn't invoke .bash_profile.
26 #
27 # Settings will take effect the next time you log in.
28 #
29 # Uninstalling
30 # ============
31 #
32 # To uninstall, just remove the line from your .bash_profile and .bashrc.
33
34 _django_completion()
35 {
36     local cur prev opts actions action_shell_opts
37     COMPREPLY=()
38     cur="${COMP_WORDS[COMP_CWORD]}"
39     prev="${COMP_WORDS[COMP_CWORD-1]}"
40
41     # Standalone options
42     opts="--help --settings --pythonpath --version"
43     # Actions
44     actions="adminindex createcachetable dbshell diffsettings \
45              inspectdb install reset runserver \
46              shell sql sqlall sqlclear sqlindexes sqlinitialdata \
47              sqlreset sqlsequencereset startapp startproject \
48              syncdb validate"
49     # Action's options
50     action_shell_opts="--plain"
51
52     if [[ # django-admin.py, ./manage, manage.py
53           ( ${COMP_CWORD} -eq 1 &&
54             ( ${COMP_WORDS[0]} == django-admin.py ||
55               ${COMP_WORDS[0]} == ./manage.py ||
56               ${COMP_WORDS[0]} == manage.py ) )
57           ||
58           # python manage.py, /some/path/python manage.py (if manage.py exists)
59           ( ${COMP_CWORD} -eq 2 &&
60             ( $( basename ${COMP_WORDS[0]} ) == python ) &&
61             ( $( basename ${COMP_WORDS[1]} ) == manage.py) &&
62             ( -r ${COMP_WORDS[1]} ) ) ]] ; then
63
64         case ${cur} in
65             -*)
66                 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
67                 return 0
68                 ;;
69             *)
70                 COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
71                 return 0
72                 ;;
73         esac
74     else
75         case ${prev} in
76             adminindex|install|reset| \
77             sql|sqlall|sqlclear|sqlindexes| \
78             sqlinitialdata|sqlreset|sqlsequencereset)
79             # App completion isn't yet implemented, but here's where that
80             # would go.
81             # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
82             COMPREPLY=()
83             return 0
84             ;;
85
86             createcachetable|dbshell|diffsettings| \
87             inspectdb|runserver|startapp|startproject|syncdb| \
88             validate)
89                 COMPREPLY=()
90                 return 0
91                 ;;
92             shell)
93                 COMPREPLY=( $(compgen -W "$action_shell_opts" -- ${cur}) )
94                 return 0
95                 ;;
96             *)
97                 #COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
98                 COMPREPLY=()
99                 return 0
100                 ;;
101         esac
102     fi
103 }
104
105 complete -F _django_completion django-admin.py manage.py
Note: See TracBrowser for help on using the browser.