I implemented app completion and would like comments and testing for
those on *nix.

What's the easiest way to provide a patch?  Open a new ticket and
attached?  Or attach it to the original bash_completion ticket here:
http://code.djangoproject.com/ticket/1240 ?  I'm pasting the diff
below so people can test for now.

A couple notes:

* My patch uses sed, grep, and tr instead of the previous patch which
uses Python.  The Python way does seem nice since Django already knows
about its own apps.  But Adrian made a comment on the ticket above
that it didn't work for him.

* Depends on settings.py being named "settings.py" and depends on the
user being in the project root directory (where settings.py is).  The
previous patch had this dependency too.

* This essentially does the following (each command):

  1. Filters settings.py and prints everything in INSTALLED_APPS
  2. Strips any lines with django in them
  3. Does pattern matching to get the app name.
  4. Finally, tr merges the separate lines into a single line with
apps separated by spaces.

It's working on my Mac.  If I type "./manage.py sql " and press tab
twice, I get a list of apps and starting to type one does tab
completion.

Comments appreciated.

-Rob

Index: extras/django_bash_completion
===================================================================
--- extras/django_bash_completion       (revision 4557)
+++ extras/django_bash_completion       (working copy)
@@ -79,10 +79,12 @@
             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=()
+            # App completion
+            apps=`sed -n '/INSTALLED_APPS = (/,/)/p' settings.py | \
+                  grep -v django |
+                  sed -n "s/^[ ]*'.*\.\(.*\)'.*$/\1 /pg" | \
+                  tr -d '\n'`
+            COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) )
             return 0
             ;;


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to