Ticket #1240: app_completion.2.diff

File app_completion.2.diff, 1.5 KB (added by Rob Hudson <treborhudson@…>, 17 years ago)

Updated patch

  • extras/django_bash_completion

     
    7979            adminindex|install|reset| \
    8080            sql|sqlall|sqlclear|sqlindexes| \
    8181            sqlinitialdata|sqlreset|sqlsequencereset)
    82             # App completion isn't yet implemented, but here's where that
    83             # would go.
    84             # COMPREPLY=( $(compgen -W "auth core" -- ${cur}) )
    85             COMPREPLY=()
     82            # App completion
     83            settings=""
     84            # If settings.py in the PWD, use that
     85            if [ -e settings.py ] ; then
     86                settings="$PWD/settings.py"
     87            else
     88                # Use the ENV variable if it is set
     89                if [ $DJANGO_SETTINGS_MODULE ] ; then
     90                    settings=$DJANGO_SETTINGS_MODULE
     91                fi
     92            fi
     93            # Couldn't find settings so return nothing
     94            if [ -z $settings ] ; then
     95                COMPREPLY=()
     96            # Otherwise inspect settings.py file
     97            else
     98                apps=`sed -n "/INSTALLED_APPS = (/,/)/p" $settings | \
     99                      grep -v "django.contrib" |
     100                      sed -n "s/^[ ]*'\(.*\.\)*\(.*\)'.*$/\2 /pg" | \
     101                      tr -d "\n"`
     102                COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) )
     103            fi
    86104            return 0
    87105            ;;
    88106
Back to Top