Ticket #1240: django.2

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

Django bash completion script updated for 0.95 (post-magic-removal)

Line 
1# #########################################################################
2# This bash script adds tab-completion feature to django-admin.py and
3# manage.py.
4#
5# Installation.
6#
7# Create a directory named .bash_completion in your home directory and move
8# this file there. Now, if in your home exists a file called .profile use this
9# one, otherwise use .bash_profile and add this line:
10#
11# source ~/.bash_completion/django
12#
13# Do the same in ~/.bashrc. Usually this shouldn't be necessary as
14# .profile or .bash_profile take care to invoke .bashrc, if it exists, but
15# different distributions handle this aspect differently.
16#
17# Settings will become effective since next login.
18#
19# Currently it is not supported models completion.
20#
21# Please, feedbacks at paolo@php3.it or at paolo on freenode. Thanks.
22
23_django_completion()
24{
25 # ###########################################
26 # Actually model completion is not supported.
27 # local models
28 # models="abc def ghi"
29
30 local cur prev opts actions action_shell_opts
31 COMPREPLY=()
32 cur="${COMP_WORDS[COMP_CWORD]}"
33 prev="${COMP_WORDS[COMP_CWORD-1]}"
34
35 # Standalone options.
36 opts="--help --settings --pythonpath --version"
37 # Actions.
38 actions="adminindex createcachetable createsuperuser \
39 init inspectdb install installperms runserver \
40 shell dbshell sql sqlall sqlclear sqlindexes sqlinitialdata \
41 sqlreset sqlsequencereset startapp startproject \
42 validate diffsettings syncdb"
43 # Action's options.
44 action_shell_opts="--plain"
45
46 if [[ # django-admin.py, ./manage, manage.py
47 ( ${COMP_CWORD} -eq 1 &&
48 ( ${COMP_WORDS[0]} == django-admin.py ||
49 ${COMP_WORDS[0]} == ./manage.py ||
50 ${COMP_WORDS[0]} == manage.py ) )
51 ||
52 # python manage.py, /some/path/python manage.py (if manage.py exists)
53 ( ${COMP_CWORD} -eq 2 &&
54 ( $( basename ${COMP_WORDS[0]} ) == python ) &&
55 ${COMP_WORDS[1]} == manage.py &&
56 ( -r manage.py ) ) ]] ; then
57
58 case ${cur} in
59 -*)
60 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
61 return 0
62 ;;
63 *)
64 COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
65 return 0
66 ;;
67 esac
68 else
69 case ${prev} in
70 adminindex|install|installperms| \
71 sql|sqlall|sqlclear|sqlindexes| \
72 sqlinitialdata|sqlreset|sqlsequencereset)
73 # Actually modelmodules completion is not supported.
74 # COMPREPLY=( $(compgen -W "$models" -- ${cur}) )
75 return 0
76 ;;
77
78 createcachetable|createsuperuser|init| \
79 inspectdb|runserver|startapp|startproject| \
80 validate)
81 COMPREPLY=()
82 return 0
83 ;;
84 shell)
85 COMPREPLY=( $(compgen -W "$action_shell_opts" -- ${cur}) )
86 return 0
87 ;;
88 *)
89 COMPREPLY=( $(compgen -W "$models" -- ${cur}) )
90 return 0
91 ;;
92 esac
93 fi
94}
95
96complete -F _django_completion django-admin.py manage.py
97complete -F _django_completion -o default python
Back to Top