Browse code

Add Django plugin. This is a slight modification of the Django zsh completions that I found at https://raw.github.com/technolize/zsh-completion-funcs/master/_manage.py

Marc Abramowitz authored on 10/06/2011 at 04:22:33
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,222 @@
0
+#compdef manage.py
1
+
2
+typeset -ga nul_args
3
+nul_args=(
4
+  '--settings=-[the Python path to a settings module.]:file:_files'
5
+  '--pythonpath=-[a directory to add to the Python path.]::directory:_directories'
6
+  '--traceback[print traceback on exception.]'
7
+  "--version[show program's version number and exit.]"
8
+  {-h,--help}'[show this help message and exit.]'
9
+)
10
+
11
+_managepy-adminindex(){
12
+  _arguments -s : \
13
+    $nul_args \
14
+    '*::directory:_directories' && ret=0
15
+}
16
+
17
+_managepy-createcachetable(){
18
+  _arguments -s : \
19
+    $nul_args && ret=0
20
+}
21
+
22
+_managepy-dbshell(){
23
+  _arguments -s : \
24
+    $nul_args && ret=0
25
+}
26
+
27
+_managepy-diffsettings(){
28
+  _arguments -s : \
29
+    $nul_args && ret=0
30
+}
31
+
32
+_managepy-dumpdata(){
33
+  _arguments -s : \
34
+    '--format=-[specifies the output serialization format for fixtures.]:format:(json yaml xml)' \
35
+    '--indent=-[specifies the indent level to use when pretty-printing output.]:' \
36
+    $nul_args \
37
+    '*::appname:_applist' && ret=0
38
+}
39
+
40
+_managepy-flush(){
41
+  _arguments -s : \
42
+    '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
43
+    '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
44
+    $nul_args && ret=0
45
+}
46
+
47
+_managepy-help(){
48
+  _arguments -s : \
49
+    '*:command:_managepy_cmds' \
50
+    $nul_args && ret=0
51
+}
52
+
53
+_managepy_cmds(){
54
+    local line
55
+    local -a cmd
56
+    _call_program help-command ./manage.py help \
57
+      |& sed -n '/^ /s/[(), ]/ /gp' \
58
+      | while read -A line; do cmd=($line $cmd) done
59
+    _describe -t managepy-command 'manage.py command' cmd
60
+}
61
+
62
+_managepy-inspectdb(){
63
+  _arguments -s : \
64
+    $nul_args && ret=0
65
+}
66
+
67
+_managepy-loaddata(){
68
+  _arguments -s : \
69
+    '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
70
+    '*::file:_files' \
71
+    $nul_args && ret=0
72
+}
73
+
74
+_managepy-reset(){
75
+  _arguments -s : \
76
+    '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
77
+    '*::appname:_applist' \
78
+    $nul_args && ret=0
79
+}
80
+
81
+_managepy-runfcgi(){
82
+  local state
83
+  
84
+  local fcgi_opts
85
+  fcgi_opts=(
86
+    'protocol[fcgi, scgi, ajp, ... (default fcgi)]:protocol:(fcgi scgi ajp)'
87
+    'host[hostname to listen on..]:'
88
+    'port[port to listen on.]:'
89
+    'socket[UNIX socket to listen on.]::file:_files'
90
+    'method[prefork or threaded (default prefork)]:method:(prefork threaded)'
91
+    'maxrequests[number of requests a child handles before it is killed and a new child is forked (0 = no limit).]:'
92
+    'maxspare[max number of spare processes / threads.]:'
93
+    'minspare[min number of spare processes / threads.]:'
94
+    'maxchildren[hard limit number of processes / threads.]:'
95
+    'daemonize[whether to detach from terminal.]:boolean:(False True)'
96
+    'pidfile[write the spawned process-id to this file.]:file:_files'
97
+    'workdir[change to this directory when daemonizing.]:directory:_files'
98
+    'outlog[write stdout to this file.]:file:_files'
99
+    'errlog[write stderr to this file.]:file:_files'
100
+  )
101
+  
102
+  _arguments -s : \
103
+    $nul_args \
104
+    '*: :_values "FCGI Setting" $fcgi_opts' && ret=0
105
+}
106
+
107
+_managepy-runserver(){
108
+  _arguments -s : \
109
+    '--noreload[tells Django to NOT use the auto-reloader.]' \
110
+    '--adminmedia[specifies the directory from which to serve admin media.]:directory:_files' \
111
+    $nul_args && ret=0
112
+}
113
+
114
+_managepy-shell(){
115
+  _arguments -s : \
116
+    '--plain[tells Django to use plain Python, not IPython.]' \
117
+    $nul_args && ret=0
118
+}
119
+
120
+_managepy-sql(){}
121
+_managepy-sqlall(){}
122
+_managepy-sqlclear(){}
123
+_managepy-sqlcustom(){}
124
+_managepy-sqlflush(){}
125
+_managepy-sqlindexes(){}
126
+_managepy-sqlinitialdata(){}
127
+_managepy-sqlreset(){}
128
+_managepy-sqlsequencereset(){}
129
+_managepy-startapp(){}
130
+
131
+_managepy-syncdb() {
132
+  _arguments -s : \
133
+    '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
134
+    '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
135
+    $nul_args && ret=0
136
+}
137
+
138
+_managepy-test() {
139
+  _arguments -s : \
140
+    '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
141
+    '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
142
+    '*::appname:_applist' \
143
+    $nul_args && ret=0
144
+}
145
+
146
+_managepy-testserver() {
147
+  _arguments -s : \
148
+    '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
149
+    '--addrport=-[port number or ipaddr:port to run the server on.]' \
150
+    '*::fixture:_files' \
151
+    $nul_args && ret=0
152
+}
153
+
154
+_managepy-validate() {
155
+  _arguments -s : \
156
+    $nul_args && ret=0
157
+}
158
+
159
+_managepy-commands() {
160
+  local -a commands
161
+  
162
+  commands=(
163
+    'adminindex:prints the admin-index template snippet for the given app name(s).'
164
+    'createcachetable:creates the table needed to use the SQL cache backend.'
165
+    'dbshell:runs the command-line client for the current DATABASE_ENGINE.'
166
+    "diffsettings:displays differences between the current settings.py and Django's default settings."
167
+    'dumpdata:Output the contents of the database as a fixture of the given format.'
168
+    'flush:Executes ``sqlflush`` on the current database.'
169
+    'help:manage.py help.'
170
+    'inspectdb:Introspects the database tables in the given database and outputs a Django model module.'
171
+    'loaddata:Installs the named fixture(s) in the database.'
172
+    'reset:Executes ``sqlreset`` for the given app(s) in the current database.'
173
+    'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,'
174
+    'runserver:Starts a lightweight Web server for development.'
175
+    'shell:Runs a Python interactive interpreter.'
176
+    'sql:Prints the CREATE TABLE SQL statements for the given app name(s).'
177
+    'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).'
178
+    'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).'
179
+    'sqlcustom:Prints the custom table modifying SQL statements for the given app name(s).'
180
+    'sqlflush:Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed.'
181
+    'sqlindexes:Prints the CREATE INDEX SQL statements for the given model module name(s).'
182
+    "sqlinitialdata:RENAMED: see 'sqlcustom'"
183
+    'sqlreset:Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).'
184
+    'sqlsequencereset:Prints the SQL statements for resetting sequences for the given app name(s).'
185
+    "startapp:Creates a Django app directory structure for the given app name in this project's directory."
186
+    "syncdb:Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
187
+    'test:Runs the test suite for the specified applications, or the entire site if no apps are specified.'
188
+    'testserver:Runs a development server with data from the given fixture(s).'
189
+    'validate:Validates all installed models.'
190
+  )
191
+  
192
+  _describe -t commands 'manage.py command' commands && ret=0
193
+}
194
+
195
+_applist() {
196
+  local line
197
+  local -a apps
198
+  _call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\
199
+                                          bn=op.basename(op.abspath(op.curdir));[sys\\
200
+                                          .stdout.write(str(re.sub(r'^%s\.(.*?)$' %
201
+                                          bn, r'\1', i)) + '\n') for i in django.conf.settings.\\
202
+                                          INSTALLED_APPS if re.match(r'^%s' % bn, i)]\"" \
203
+                             | while read -A line; do apps=($line $apps) done
204
+  _values 'Application' $apps && ret=0
205
+}
206
+
207
+_managepy() {
208
+  local curcontext=$curcontext ret=1
209
+  
210
+  if ((CURRENT == 2)); then
211
+    _managepy-commands
212
+  else
213
+    shift words
214
+    (( CURRENT -- ))
215
+    curcontext="${curcontext%:*:*}:managepy-$words[1]:"
216
+    _call_function ret _managepy-$words[1]
217
+  fi
218
+}
219
+
220
+compdef _managepy manage.py
221
+compdef _managepy django