| 1 | == Bash auto-completion for {{{django-admin.py}}}/{{{manage.py}}} == |
| 2 | |
| 3 | Can't you remember the options for django-admin.py or are you just plain lazy as me, then the following little script might be something for you. |
| 4 | |
| 5 | The following script will add auto completion to {{{django-admin.py}}} and {{{manage.py}}} for actions and options. It has the latest actions and options from trunk 5833. The script is limited to only auto-completing the actions and options. The script won't e.g find your application names if you type {{{manage.py adminindex somepartialappname<TAB>}}}. |
| 6 | |
| 7 | === Installation === |
| 8 | To install it, copy the script below and save it e.g. in a file {{{~/.djangocompletion.sh}}}. In your {{{~/.profile}}} you just run the script by e.g. adding the follwoing line: |
| 9 | |
| 10 | {{{ |
| 11 | source ~/.djangocompletion.sh |
| 12 | }}} |
| 13 | |
| 14 | You may also add the script directly in your {{{.profile}}} file. |
| 15 | |
| 16 | === Bash script === |
| 17 | {{{ |
| 18 | #!/bin/sh |
| 19 | # |
| 20 | # Initial author: Lars Holm Nielsen <lars@hankat.dk> |
| 21 | # Copyright-free |
| 22 | |
| 23 | _djangoadmin_complete() |
| 24 | { |
| 25 | # manage.py action [options] |
| 26 | local cur prev actions base |
| 27 | COMPREPLY=() |
| 28 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 29 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 30 | base="${COMP_WORDS[1]}" |
| 31 | |
| 32 | # |
| 33 | # Completion list of commands |
| 34 | # |
| 35 | actions='adminindex createcachetable dbshell diffsettings dumpdata flush inspectdb loaddata reset runfcgi runserver shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes sqlreset sqlsequencereset startapp syncdb test validate' |
| 36 | |
| 37 | if [ "${prev##*/}" = "django-admin.py" ] |
| 38 | then |
| 39 | COMPREPLY=($(compgen -W "$actions" -- "$cur")) |
| 40 | return 0 |
| 41 | fi |
| 42 | |
| 43 | if [ "${prev##*/}" = "manage.py" ] |
| 44 | then |
| 45 | COMPREPLY=($(compgen -W "$actions" -- "$cur")) |
| 46 | return 0 |
| 47 | fi |
| 48 | |
| 49 | local results |
| 50 | |
| 51 | # |
| 52 | # Complete the arguments to some of the basic commands. |
| 53 | # |
| 54 | case "${base}" in |
| 55 | # [appname ...] |
| 56 | adminindex|sql|sqlall|sqlclear|sqlcustom|sqlindexes|sqlreset|sqlsequencereset) |
| 57 | results='' |
| 58 | ;; |
| 59 | # [tablename] |
| 60 | createcachetable) |
| 61 | results='' |
| 62 | ;; |
| 63 | # [--format=FORMAT] [--indent=INDENT] [appname ...] |
| 64 | dumpdata) |
| 65 | results='--format= --indent=' |
| 66 | ;; |
| 67 | # [--verbosity=VERBOSITY] [--noinput] |
| 68 | syncdb|flush) |
| 69 | results='--verbosity= --noinput' |
| 70 | ;; |
| 71 | # [--verbosity=VERBOSITY] fixture, fixture, ... |
| 72 | loaddata) |
| 73 | results='--verbosity=VERBOSITY' |
| 74 | ;; |
| 75 | # [--noinput][appname ...] |
| 76 | reset) |
| 77 | results='--noinput' |
| 78 | ;; |
| 79 | # [various KEY=val options, use `runfcgi help` for help] |
| 80 | runfcgi) |
| 81 | results='help' |
| 82 | ;; |
| 83 | # [--noreload] [--adminmedia=ADMIN_MEDIA_PATH] [optional port number, or ipaddr:port] |
| 84 | runserver) |
| 85 | results='--noreload --adminmedia=' |
| 86 | ;; |
| 87 | # [--plain] |
| 88 | shell) |
| 89 | results='--plain' |
| 90 | ;; |
| 91 | # [appname] |
| 92 | startapp) |
| 93 | results='' |
| 94 | ;; |
| 95 | # [--verbosity=VERBOSITY] [--noinput] [appname ...] |
| 96 | test) |
| 97 | results='--verbosity= --noinput' |
| 98 | ;; |
| 99 | esac |
| 100 | |
| 101 | results="$results --version -h --help --settings= --pythonpath=" |
| 102 | |
| 103 | COMPREPLY=($(compgen -W "$results" -- "$cur")) |
| 104 | return 0 |
| 105 | } |
| 106 | |
| 107 | complete -F _djangoadmin_complete django-admin.py |
| 108 | complete -F _djangoadmin_complete manage.py |
| 109 | }}} |
| 110 | |
| 111 | === Bugs === |
| 112 | Since I'm not a big shell programmer, there's probably some bugs in the script. Feel free to edit the script if you find any or add more features to it. |