django.plugin.zsh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. #compdef manage.py
  2. typeset -ga nul_args
  3. nul_args=(
  4. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))'
  5. '--settings=-[the Python path to a settings module.]:file:_files'
  6. '--pythonpath=-[a directory to add to the Python path.]:directory:_directories'
  7. '--traceback[print traceback on exception.]'
  8. "--no-color[Don't colorize the command output.]"
  9. "--version[show program's version number and exit.]"
  10. {-h,--help}'[show this help message and exit.]'
  11. )
  12. typeset -ga start_args
  13. start_args=(
  14. '--template=-[The path or URL to load the template from.]:directory:_directories'
  15. '--extension=-[The file extension(s) to render (default: "py").]'
  16. '--name=-[The file name(s) to render.]:file:_files'
  17. )
  18. typeset -ga db_args
  19. db_args=(
  20. '--database=-[Nominates a database. Defaults to the "default" database.]'
  21. )
  22. typeset -ga noinput_args
  23. noinput_args=(
  24. '--noinput[tells Django to NOT prompt the user for input of any kind.]'
  25. )
  26. typeset -ga no_init_data_args
  27. no_init_data_args=(
  28. '--no-initial-data[Tells Django not to load any initial data after database synchronization.]'
  29. )
  30. typeset -ga tag_args
  31. tag_args=(
  32. '--tag=-[Run only checks labeled with given tag.]'
  33. '--list-tags[List available tags.]'
  34. )
  35. _managepy-check(){
  36. _arguments -s : \
  37. $tag_args \
  38. $nul_args && ret=0
  39. }
  40. _managepy-changepassword(){
  41. _arguments -s : \
  42. $db_args \
  43. $nul_args && ret=0
  44. }
  45. _managepy-createcachetable(){
  46. _arguments -s : \
  47. $db_args \
  48. $nul_args && ret=0
  49. }
  50. _managepy-createsuperuser(){
  51. _arguments -s : \
  52. '--username=-[Specifies the login for the superuser.]' \
  53. '--email=-[Specifies the email for the superuser.]' \
  54. $noinput_args \
  55. $db_args \
  56. $nul_args && ret=0
  57. }
  58. _managepy-collectstatic(){
  59. _arguments -s : \
  60. '--link[Create a symbolic link to each file instead of copying.]' \
  61. '--no-post-process[Do NOT post process collected files.]' \
  62. '--ignore=-[Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.]' \
  63. '--dry-run[Do everything except modify the filesystem.]' \
  64. '--clear[Clear the existing files using the storage before trying to copy or link the original file.]' \
  65. '--link[Create a symbolic link to each file instead of copying.]' \
  66. '--no-default-ignore[Do not ignore the common private glob-style patterns "CVS", ".*" and "*~".]' \
  67. $noinput_args \
  68. $nul_args && ret=0
  69. }
  70. _managepy-dbshell(){
  71. _arguments -s : \
  72. $db_args \
  73. $nul_args && ret=0
  74. }
  75. _managepy-diffsettings(){
  76. _arguments -s : \
  77. "--all[Display all settings, regardless of their value.]"
  78. $nul_args && ret=0
  79. }
  80. _managepy-dumpdata(){
  81. _arguments -s : \
  82. '--format=-[Specifies the output serialization format for fixtures.]:format:(json yaml xml)' \
  83. '--indent=-[Specifies the indent level to use when pretty-printing output.]' \
  84. '--exclude=-[An app_label or app_label.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).]' \
  85. '--natural-foreign[Use natural foreign keys if they are available.]' \
  86. '--natural-primary[Use natural primary keys if they are available.]' \
  87. "--all[Use Django's base manager to dump all models stored in the database.]" \
  88. '--pks=-[Only dump objects with given primary keys.]' \
  89. $db_args \
  90. $nul_args \
  91. '*::appname:_applist' && ret=0
  92. }
  93. _managepy-flush(){
  94. _arguments -s : \
  95. $no_init_data_args \
  96. $db_args \
  97. $noinput_args \
  98. $nul_args && ret=0
  99. }
  100. _managepy-help(){
  101. _arguments -s : \
  102. '*:command:_managepy_cmds' \
  103. $nul_args && ret=0
  104. }
  105. _managepy_cmds(){
  106. local line
  107. local -a cmd
  108. _call_program help-command ./manage.py help \
  109. |& sed -n '/^ /s/[(), ]/ /gp' \
  110. | while read -A line; do cmd=($line $cmd) done
  111. _describe -t managepy-command 'manage.py command' cmd
  112. }
  113. _managepy-inspectdb(){
  114. _arguments -s : \
  115. $db_args \
  116. $nul_args && ret=0
  117. }
  118. _managepy-loaddata(){
  119. _arguments -s : \
  120. '--ignorenonexistent[Ignores entries in the serialized data for fields that do not currently exist on the model.]' \
  121. '--app=-[Only look for fixtures in the specified app.]:appname:_applist' \
  122. '*::file:_files' \
  123. $db_args \
  124. $nul_args && ret=0
  125. }
  126. _managepy-makemessages(){
  127. _arguments -s : \
  128. '--locale=-[Creates or updates the message files for the given locale(s) (e.g. pt_BR).]' \
  129. '--domain=-[The domain of the message files (default: "django").]' \
  130. '--all[Updates the message files for all existing locales.]' \
  131. '--extension=-[The file extension(s) to examine (default: "html,txt", or "js" if the domain is "djangojs").]' \
  132. '--symlinks[Follows symlinks to directories when examining source code and templates for translation strings.]' \
  133. '--ignore=-[Ignore files or directories matching this glob-style pattern.]' \
  134. "--no-default-ignore[Don't ignore the common glob-style patterns 'CVS', '.*', '*~' and '*.pyc'.]" \
  135. "--no-wrap[Don't break long message lines into several lines.]" \
  136. "--no-location[Don't write '#: filename:line' lines.]" \
  137. '--no-obsolete[Remove obsolete message strings.]' \
  138. '--keep-pot[Keep .pot file after making messages.]' \
  139. $nul_args && ret=0
  140. }
  141. _managepy-makemigrations(){
  142. _arguments -s : \
  143. '--dry-run[Just show what migrations would be made]' \
  144. '--merge[Enable fixing of migration conflicts.]' \
  145. '--empty[Create an empty migration.]' \
  146. $noinput_args \
  147. $nul_args && ret=0
  148. }
  149. _managepy-migrate(){
  150. _arguments -s : \
  151. '--fake[Mark migrations as run without actually running them]' \
  152. '--list[Show a list of all known migrations and which are applied]' \
  153. $no_init_data_args \
  154. $noinput_args \
  155. $db_args \
  156. $nul_args && ret=0
  157. }
  158. _managepy-runfcgi(){
  159. local state
  160. local fcgi_opts
  161. fcgi_opts=(
  162. 'protocol[fcgi, scgi, ajp, ... (default fcgi)]:protocol:(fcgi scgi ajp)'
  163. 'host[hostname to listen on..]:'
  164. 'port[port to listen on.]:'
  165. 'socket[UNIX socket to listen on.]:file:_files'
  166. 'method[prefork or threaded (default prefork)]:method:(prefork threaded)'
  167. 'maxrequests[number of requests a child handles before it is killed and a new child is forked (0 = no limit).]:'
  168. 'maxspare[max number of spare processes / threads.]:'
  169. 'minspare[min number of spare processes / threads.]:'
  170. 'maxchildren[hard limit number of processes / threads.]:'
  171. 'daemonize[whether to detach from terminal.]:boolean:(False True)'
  172. 'pidfile[write the spawned process-id to this file.]:file:_files'
  173. 'workdir[change to this directory when daemonizing.]:directory:_files'
  174. 'outlog[write stdout to this file.]:file:_files'
  175. 'errlog[write stderr to this file.]:file:_files'
  176. )
  177. _arguments -s : \
  178. $nul_args \
  179. '*: :_values "FCGI Setting" $fcgi_opts' && ret=0
  180. }
  181. _managepy-runserver(){
  182. _arguments -s : \
  183. '--ipv6[Tells Django to use an IPv6 address.]' \
  184. '--nothreading[Tells Django to NOT use threading.]' \
  185. '--noreload[Tells Django to NOT use the auto-reloader.]' \
  186. '--nostatic[Tells Django to NOT automatically serve static files at STATIC_URL.]' \
  187. '--insecure[Allows serving static files even if DEBUG is False.]' \
  188. $nul_args && ret=0
  189. }
  190. _managepy-shell(){
  191. _arguments -s : \
  192. '--plain[Tells Django to use plain Python, not IPython.]' \
  193. '--no-startup[When using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.]' \
  194. '--interface=-[Specify an interactive interpreter interface.]:INTERFACE:((ipython bpython))' \
  195. $nul_args && ret=0
  196. }
  197. _managepy-sql(){
  198. _arguments -s : \
  199. $db_args \
  200. $nul_args && ret=0
  201. }
  202. _managepy-sqlall(){
  203. _arguments -s : \
  204. $db_args \
  205. $nul_args && ret=0
  206. }
  207. _managepy-sqlclear(){
  208. _arguments -s : \
  209. $db_args \
  210. $nul_args && ret=0
  211. }
  212. _managepy-sqlcustom(){
  213. _arguments -s : \
  214. $db_args \
  215. $nul_args && ret=0
  216. }
  217. _managepy-dropindexes(){
  218. _arguments -s : \
  219. $db_args \
  220. $nul_args && ret=0
  221. }
  222. _managepy-sqlflush(){
  223. _arguments -s : \
  224. $db_args \
  225. $nul_args && ret=0
  226. }
  227. _managepy-sqlindexes(){
  228. _arguments -s : \
  229. $db_args \
  230. $nul_args && ret=0
  231. }
  232. _managepy-sqlinitialdata(){
  233. _arguments -s : \
  234. $nul_args && ret=0
  235. }
  236. _managepy-sqlsequencereset(){
  237. _arguments -s : \
  238. $db_args \
  239. $nul_args && ret=0
  240. }
  241. _managepy-squashmigrations(){
  242. _arguments -s : \
  243. '--no-optimize[Do not try to optimize the squashed operations.]' \
  244. $noinput_args \
  245. $nul_args && ret=0
  246. }
  247. _managepy-startapp(){
  248. _arguments -s : \
  249. $start_args \
  250. $nul_args && ret=0
  251. }
  252. _managepy-startproject(){
  253. _arguments -s : \
  254. $start_args \
  255. $nul_args && ret=0
  256. }
  257. _managepy-syncdb() {
  258. _arguments -s : \
  259. $noinput_args \
  260. $no_init_data_args \
  261. $db_args \
  262. $nul_args && ret=0
  263. }
  264. _managepy-test() {
  265. _arguments -s : \
  266. '--failfast[Tells Django to stop running the test suite after first failed test.]' \
  267. '--testrunner=-[Tells Django to use specified test runner class instead of the one specified by the TEST_RUNNER setting.]' \
  268. '--liveserver=-[Overrides the default address where the live server (used with LiveServerTestCase) is expected to run from. The default value is localhost:8081.]' \
  269. '--top-level-directory=-[Top level of project for unittest discovery.]' \
  270. '--pattern=-[The test matching pattern. Defaults to test*.py.]:' \
  271. $noinput_args \
  272. '*::appname:_applist' \
  273. $nul_args && ret=0
  274. }
  275. _managepy-testserver() {
  276. _arguments -s : \
  277. '--addrport=-[port number or ipaddr:port to run the server on.]' \
  278. '--ipv6[Tells Django to use an IPv6 address.]' \
  279. $noinput_args \
  280. '*::fixture:_files' \
  281. $nul_args && ret=0
  282. }
  283. _managepy-validate() {
  284. _arguments -s : \
  285. $tag_args \
  286. $nul_args && ret=0
  287. }
  288. _managepy-commands() {
  289. local -a commands
  290. commands=(
  291. "changepassword:Change a user's password for django.contrib.auth."
  292. 'check:Checks the entire Django project for potential problems.'
  293. 'compilemessages:Compiles .po files to .mo files for use with builtin gettext support.'
  294. 'createcachetable:Creates the table needed to use the SQL cache backend.'
  295. 'createsuperuser:Used to create a superuser.'
  296. 'collectstatic:Collect static files in a single location.'
  297. 'dbshell:Runs the command-line client for the current DATABASE_ENGINE.'
  298. "diffsettings:Displays differences between the current settings.py and Django's default settings."
  299. 'dumpdata:Output the contents of the database as a fixture of the given format.'
  300. 'flush:Executes ``sqlflush`` on the current database.'
  301. 'help:manage.py help.'
  302. 'inspectdb:Introspects the database tables in the given database and outputs a Django model module.'
  303. 'loaddata:Installs the named fixture(s) in the database.'
  304. 'makemessages:Runs over the entire source tree of the current directory and pulls out all strings marked for translation.'
  305. 'makemigrations:Creates new migration(s) for apps.'
  306. 'migrate:Updates database schema. Manages both apps with migrations and those without.'
  307. 'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,'
  308. 'runserver:Starts a lightweight Web server for development.'
  309. 'shell:Runs a Python interactive interpreter.'
  310. 'showmigrations:Shows all available migrations for the current project.'
  311. 'sql:Prints the CREATE TABLE SQL statements for the given app name(s).'
  312. 'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).'
  313. 'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).'
  314. 'sqlcustom:Prints the custom table modifying SQL statements for the given app name(s).'
  315. 'sqldropindexes:Prints the DROP INDEX SQL statements for the given model module name(s).'
  316. '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.'
  317. 'sqlindexes:Prints the CREATE INDEX SQL statements for the given model module name(s).'
  318. "sqlinitialdata:RENAMED: see 'sqlcustom'"
  319. 'sqlsequencereset:Prints the SQL statements for resetting sequences for the given app name(s).'
  320. 'squashmigrations:Squashes an existing set of migrations (from first until specified) into a single new one.'
  321. "startapp:Creates a Django app directory structure for the given app name in this project's directory."
  322. "startproject:Creates a Django project directory structure for the given project name in this current directory."
  323. "syncdb:Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
  324. 'test:Runs the test suite for the specified applications, or the entire site if no apps are specified.'
  325. 'testserver:Runs a development server with data from the given fixture(s).'
  326. 'validate:Validates all installed models.'
  327. )
  328. _describe -t commands 'manage.py command' commands && ret=0
  329. }
  330. _applist() {
  331. local line
  332. local -a apps
  333. _call_program help-command "python -c \"import sys; del sys.path[0];\\
  334. import os.path as op, re, django.conf;\\
  335. bn=op.basename(op.abspath(op.curdir));[sys\\
  336. .stdout.write(str(re.sub(r'^%s\.(.*?)$' %
  337. bn, r'\1', i)) + '\n') for i in django.conf.settings.\\
  338. INSTALLED_APPS if re.match(r'^%s' % bn, i)]\"" \
  339. | while read -A line; do apps=($line $apps) done
  340. _values 'Application' $apps && ret=0
  341. }
  342. _managepy() {
  343. local curcontext=$curcontext ret=1
  344. if ((CURRENT == 2)); then
  345. _managepy-commands
  346. else
  347. shift words
  348. (( CURRENT -- ))
  349. curcontext="${curcontext%:*:*}:managepy-$words[1]:"
  350. _call_function ret _managepy-$words[1]
  351. fi
  352. }
  353. compdef _managepy manage.py
  354. compdef _managepy django
  355. compdef _managepy django-admin
  356. compdef _managepy django-admin.py
  357. compdef _managepy django-manage
  358. print -P "%F{yellow}The django plugin is deprecated in favor of Zsh's Django completion.
  359. %BPlease remove it from your plugins to stop using it.%b%f"