123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- shopt -s extglob
- _django_completion()
- {
- local cur prev opts actions action_shell_opts action_runfcgi_opts
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
-
- opts="--help --settings --pythonpath --noinput --noreload --format --indent --verbosity --adminmedia --version --locale --domain"
-
- actions="createcachetable createsuperuser compilemessages \
- dbshell diffsettings dumpdata flush inspectdb loaddata \
- makemessages reset runfcgi runserver shell sql sqlall sqlclear \
- sqlcustom sqlflush sqlindexes sqlreset sqlsequencereset startapp \
- startproject syncdb test validate"
-
- action_shell_opts="--plain"
- action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
- if [[
- ( ${COMP_CWORD} -eq 1 &&
- ( ${COMP_WORDS[0]} == django-admin.py ||
- ${COMP_WORDS[0]} == django-admin ||
- ${COMP_WORDS[0]} == ./manage.py ||
- ${COMP_WORDS[0]} == manage.py ) )
- ||
-
- ( ${COMP_CWORD} -eq 2 &&
- ( $( basename -- ${COMP_WORDS[0]} ) == python?([1-9]\.[0-9]) ) &&
- ( $( basename -- ${COMP_WORDS[1]} ) == manage.py) &&
- ( -r ${COMP_WORDS[1]} ) )
- ||
- ( ${COMP_CWORD} -eq 2 &&
- ( $( basename -- ${COMP_WORDS[0]} ) == python?([1-9]\.[0-9]) ) &&
- ( $( basename -- ${COMP_WORDS[1]} ) == django-admin.py) &&
- ( -r ${COMP_WORDS[1]} ) )
- ||
- ( ${COMP_CWORD} -eq 2 &&
- ( $( basename -- ${COMP_WORDS[0]} ) == python?([1-9]\.[0-9]) ) &&
- ( $( basename -- ${COMP_WORDS[1]} ) == django-admin) &&
- ( -r ${COMP_WORDS[1]} ) ) ]] ; then
- case ${cur} in
- -*)
- COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
- action=$COMPREPLY
- return 0
- ;;
- *)
- COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
- action=$COMPREPLY
- return 0
- ;;
- esac
- else
- case ${prev} in
- dumpdata|reset| \
- sql|sqlall|sqlclear|sqlcustom|sqlindexes| \
- sqlreset|sqlsequencereset|test)
-
- settings=""
-
- if [ -e settings.py ] ; then
- settings="$PWD/settings.py"
- else
-
- if [ $DJANGO_SETTINGS_MODULE ] ; then
- settings=$DJANGO_SETTINGS_MODULE
- fi
- fi
-
- if [ -z $settings ] ; then
- COMPREPLY=()
-
- else
- apps=`sed -n "/INSTALLED_APPS = (/,/)/p" $settings | \
- grep -v "django.contrib" |
- sed -n "s/^[ ]*'\(.*\.\)*\(.*\)'.*$/\2 /pg" | \
- tr -d "\n"`
- COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) )
- fi
- return 0
- ;;
- createcachetable|cleanup|compilemessages|dbshell| \
- diffsettings|inspectdb|makemessages| \
- runserver|startapp|startproject|syncdb| \
- validate)
- COMPREPLY=()
- return 0
- ;;
- shell)
- COMPREPLY=( $(compgen -W "$action_shell_opts" -- ${cur}) )
- return 0
- ;;
- runfcgi)
- COMPREPLY=( $(compgen -W "$action_runfcgi_opts" -- ${cur}) )
- return 0
- ;;
- host*|port*|socket*|method*|maxspare*|minspare*|maxchildren*|daemonize*|pidfile*|workdir*)
- if [ "$action" == "runfcgi" ] ; then
- COMPREPLY=( $(compgen -W "$action_runfcgi_opts" -- ${cur}) )
- return 0
- fi
- return 0
- ;;
- *)
-
- COMPREPLY=()
- return 0
- ;;
- esac
- fi
- }
- complete -F _django_completion django-admin.py manage.py django-admin
- unset pythons
- if command -v whereis &>/dev/null; then
- python_interpreters=$(whereis python | cut -d " " -f 2-)
- for python in $python_interpreters; do
- pythons="${pythons} $(basename -- $python)"
- done
- pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
- else
- pythons=python
- fi
- complete -F _django_completion -o default $pythons
|