diff options
Diffstat (limited to 'extras/django_bash_completion')
| -rw-r--r-- | extras/django_bash_completion | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/extras/django_bash_completion b/extras/django_bash_completion index 829756c371..8906609a68 100644 --- a/extras/django_bash_completion +++ b/extras/django_bash_completion @@ -31,6 +31,9 @@ # # To uninstall, just remove the line from your .bash_profile and .bashrc. +# Enable extended pattern matching operators. +shopt -s extglob + _django_completion() { local cur prev opts actions action_shell_opts action_runfcgi_opts @@ -39,13 +42,13 @@ _django_completion() prev="${COMP_WORDS[COMP_CWORD-1]}" # Standalone options - opts="--help --settings --pythonpath --version" + opts="--help --settings --pythonpath --noinput --noreload --format --indent --verbosity --adminmedia --version" # Actions actions="adminindex createcachetable dbshell diffsettings \ - inspectdb install reset runfcgi runserver \ - shell sql sqlall sqlclear sqlindexes sqlinitialdata \ + dumpdata flush inspectdb loaddata reset runfcgi runserver \ + shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes \ sqlreset sqlsequencereset startapp startproject \ - syncdb validate" + syncdb test validate" # Action's options action_shell_opts="--plain" action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir" @@ -58,8 +61,13 @@ _django_completion() || # python manage.py, /some/path/python manage.py (if manage.py exists) ( ${COMP_CWORD} -eq 2 && - ( $( basename ${COMP_WORDS[0]} ) == python ) && + ( $( 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]} ) ) ]] ; then case ${cur} in @@ -76,15 +84,33 @@ _django_completion() esac else case ${prev} in - adminindex|install|reset| \ - sql|sqlall|sqlclear|sqlindexes| \ - sqlinitialdata|sqlreset|sqlsequencereset) - # App completion isn't yet implemented, but here's where that - # would go. - # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) ) - COMPREPLY=() - return 0 - ;; + adminindex|dumpdata|reset| \ + sql|sqlall|sqlclear|sqlcustom|sqlindexes| \ + sqlreset|sqlsequencereset|test) + # App completion + settings="" + # If settings.py in the PWD, use that + if [ -e settings.py ] ; then + settings="$PWD/settings.py" + else + # Use the ENV variable if it is set + if [ $DJANGO_SETTINGS_MODULE ] ; then + settings=$DJANGO_SETTINGS_MODULE + fi + fi + # Couldn't find settings so return nothing + if [ -z $settings ] ; then + COMPREPLY=() + # Otherwise inspect settings.py file + 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|dbshell|diffsettings| \ inspectdb|runserver|startapp|startproject|syncdb| \ @@ -117,3 +143,17 @@ _django_completion() } complete -F _django_completion django-admin.py manage.py + +# Support for multiple interpreters. +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 |
