Ticket #1240: django.3

File django.3, 3.9 KB (added by paolo <paolo@…>, 18 years ago)

Django bash completion script updated to reflect changes happened in #1736

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 action_runfcgi_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 runfcgi 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 action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
52
53 if [[ # django-admin.py, ./manage, manage.py
54 ( ${COMP_CWORD} -eq 1 &&
55 ( ${COMP_WORDS[0]} == django-admin.py ||
56 ${COMP_WORDS[0]} == ./manage.py ||
57 ${COMP_WORDS[0]} == manage.py ) )
58 ||
59 # python manage.py, /some/path/python manage.py (if manage.py exists)
60 ( ${COMP_CWORD} -eq 2 &&
61 ( $( basename ${COMP_WORDS[0]} ) == python ) &&
62 ( $( basename ${COMP_WORDS[1]} ) == manage.py) &&
63 ( -r ${COMP_WORDS[1]} ) ) ]] ; then
64
65 case ${cur} in
66 -*)
67 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
68 action=$COMPREPLY
69 return 0
70 ;;
71 *)
72 COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
73 action=$COMPREPLY
74 return 0
75 ;;
76 esac
77 else
78 case ${prev} in
79 adminindex|install|reset| \
80 sql|sqlall|sqlclear|sqlindexes| \
81 sqlinitialdata|sqlreset|sqlsequencereset)
82 # App completion isn't yet implemented, but here's where that
83 # would go.
84 # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
85 COMPREPLY=()
86 return 0
87 ;;
88
89 createcachetable|dbshell|diffsettings| \
90 inspectdb|runserver|startapp|startproject|syncdb| \
91 validate)
92 COMPREPLY=()
93 return 0
94 ;;
95 shell)
96 COMPREPLY=( $(compgen -W "$action_shell_opts" -- ${cur}) )
97 return 0
98 ;;
99 runfcgi)
100 COMPREPLY=( $(compgen -W "$action_runfcgi_opts" -- ${cur}) )
101 return 0
102 ;;
103 host*|port*|socket*|method*|maxspare*|minspare*|maxchildren*|daemonize*|pidfile*|workdir*)
104 if [ "$action" == "runfcgi" ] ; then
105 COMPREPLY=( $(compgen -W "$action_runfcgi_opts" -- ${cur}) )
106 return 0
107 fi
108 return 0
109 ;;
110 *)
111 #COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
112 COMPREPLY=()
113 return 0
114 ;;
115 esac
116 fi
117}
118
119complete -F _django_completion django-admin.py manage.py
Back to Top