Django

Code

Ticket #1240 (closed: fixed)

Opened 3 years ago

Last modified 3 months ago

Tab-completion actions for django-admin

Reported by: paolo <paolo@php3.it> Assigned to: adrian
Milestone: Component: django-admin.py
Version: SVN Keywords:
Cc: paolo@php3.it, treborhudson@gmail.com, wonlay@gmail.com Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Tab-completion actions for django-admin

This ticket exists because after reading LittleEasyImprovements wiki page I have been attracted by "Tab-completion actions for django-admin" project. So I decided to write a bash script for that purpose.

The script is attached below, and adds tab completion capability to django-admin.py and manage.py (./manage.py, python manage.py, python project/manage.py, etc.), even if it is only partially supported: actually only actions (adminindex, createcachetable, createsuperuser, etc.) and options (--help, --settings, etc.) are handled, while models completion is not, mainly because I was not able to write Python code that returns names of models installed within a project (auth, core, and the ones created by the user). Any help on this would be greatly appreciated!

I hope you can find the script useful in some way, even if not finished. Feel free to use it as you want, if you want. It has been a pleasure to do something for you, in each case.

Installation

Create a directory named .bash_completion in your home directory and move this file there. Now, if in your home exists a file called .profile use this one, otherwise use .bash_profile and add this line:

source ~/.bash_completion/django

Do the same in ~/.bashrc. Usually this shouldn't be necessary as .profile or .bash_profile take care to invoke .bashrc, if it exists, but different distributions handle this aspect differently.

Settings will become effective since next login, or after typing source ~/.bash_completion/django

Attachments

django (3.2 kB) - added by paolo <paolo@php3.it> on 01/18/06 09:02:12.
django.2 (3.2 kB) - added by paolo <paolo@php3.it> on 05/21/06 04:50:39.
Django bash completion script updated for 0.95 (post-magic-removal)
django.3 (3.9 kB) - added by paolo <paolo@php3.it> on 06/21/06 05:21:45.
Django bash completion script updated to reflect changes happened in #1736
appname-completion.diff (1.5 kB) - added by scott@clued-in.co.uk on 06/29/06 08:19:53.
[patch] appname completion
app_completion.diff (0.9 kB) - added by Rob Hudson <treborhudson@gmail.com> on 02/23/07 11:02:50.
Adding app completion to existing bash script using standard unix tools (sed, grep, tr).
app_completion.2.diff (1.5 kB) - added by Rob Hudson <treborhudson@gmail.com> on 02/24/07 12:12:00.
Updated patch
a_better_app_completion.diff (0.8 kB) - added by paolo <paolo@php3.it> on 02/25/07 15:40:45.
A patch to improve application name completion
support_for_multiple_interpreters.diff (1.6 kB) - added by paolo <paolo@php3.it> on 02/26/07 11:08:56.
Updated patch against the trunk
support_for_multiple_interpreters_mac.diff (0.5 kB) - added by paolo@php3.it on 02/28/07 17:39:12.
django_bash_completion.diff (0.6 kB) - added by Wonlay on 07/08/08 22:48:21.
Fix problems when tabs are used for indent of settings.py

Change History

01/18/06 09:02:12 changed by paolo <paolo@php3.it>

  • attachment django added.

02/27/06 06:38:14 changed by apgwoz (aaaaat) gmail (tod) com

  • severity changed from normal to minor.

Rather than use source to run the script, . should be used as it doesn't create a new process to run the script.

instead of source ~/.bash_completion/django

. ~/.bash_completion/django

04/23/06 18:52:41 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [2742]) magic-removal: Fixed #1240 -- Added Django bash completion script in new extras/ directory. Thanks, paolo

05/21/06 04:50:39 changed by paolo <paolo@php3.it>

  • attachment django.2 added.

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

05/21/06 04:55:24 changed by paolo <paolo@php3.it>

  • status changed from closed to reopened.
  • resolution deleted.

The script has been updated to reflect new django-admin.py and manage.py actions and options (dbshell, diffsettings, syncdb, --version). It is available as attachment named django.2

06/02/06 00:47:08 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

Fixed. This new patch appears to offer no new functionality over what's currently in Django's trunk.

06/21/06 05:21:45 changed by paolo <paolo@php3.it>

  • attachment django.3 added.

Django bash completion script updated to reflect changes happened in #1736

06/21/06 05:23:54 changed by anonymous

  • cc set to paolo@php3.it.
  • status changed from closed to reopened.
  • resolution deleted.

06/21/06 06:13:33 changed by mtredinnick

Next time (and I'm sure there will be a next time), could you post a diff please, rather than the whole file. It makes it slightly faster to review. Thanks. :-)

06/21/06 06:15:01 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [3187]) Fixed #1240 -- Updated bash completion file to accomodate changes in r3174. Thanks, Paolo.

06/29/06 08:19:53 changed by scott@clued-in.co.uk

  • attachment appname-completion.diff added.

[patch] appname completion

07/02/06 07:32:27 changed by

  • status changed from closed to reopened.
  • resolution deleted.

[patch] appname completion

07/04/06 22:46:15 changed by hi-world cup

  • cc changed from paolo@php3.it to hi-world, cup.
  • keywords set to rthml tab space editor js.
  • summary changed from Tab-completion actions for django-admin to hi-world cup.

07/04/06 22:54:08 changed by adrian

  • summary changed from hi-world cup to Tab-completion actions for django-admin.

07/05/06 01:31:25 changed by paolo

  • cc changed from hi-world, cup to paolo@php3.it.
  • keywords deleted.

07/07/06 15:11:21 changed by anonymous

  • severity changed from minor to normal.
  • component changed from django-admin.py to Generic views.
  • priority changed from normal to high.
  • version set to magic-removal.
  • milestone set to Version 0.92.
  • type changed from enhancement to task.

07/07/06 17:32:49 changed by paolo <paolo@php3.it>

  • severity changed from normal to minor.
  • component changed from Generic views to django-admin.py.
  • priority changed from high to normal.
  • version changed from magic-removal to SVN.
  • milestone deleted.
  • type changed from task to enhancement.

08/05/06 18:22:56 changed by adrian

  • status changed from reopened to closed.
  • resolution set to invalid.

I couldn't get this latest patch (the one that autocompletes app names) to work.

02/23/07 04:54:36 changed by afternoon@uk2.net

  • keywords set to http status response.

The latest patch doesn't apply for me. Did you use svn diff to generate it?

02/23/07 11:01:44 changed by Rob Hudson <treborhudson@gmail.com>

  • cc changed from paolo@php3.it to paolo@php3.it, treborhudson@gmail.com.
  • keywords deleted.
  • has_patch set to 1.
  • status changed from closed to reopened.
  • resolution deleted.

Re-opening ticket to add my app completion support.

Tested on: * Mac OS 10.4 * Ubuntu Linux

See this thread for more: http://groups.google.com/group/django-developers/browse_thread/thread/284c81cf24ff8e2b/#

02/23/07 11:02:50 changed by Rob Hudson <treborhudson@gmail.com>

  • attachment app_completion.diff added.

Adding app completion to existing bash script using standard unix tools (sed, grep, tr).

02/24/07 05:26:52 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Ready for checkin.

02/24/07 06:11:36 changed by afternoon@uk2.net

The patch does now apply (thanks!) but it assumes I'm in the working directory for the project, settings.py is just grabbed from the PWD. I don't tend to be in my project dir when I invoke django-admin.py so I get sed errors on hitting tab.

One other related thing, test is not included in the list of verbs. That's a separate bug though.

02/24/07 12:12:00 changed by Rob Hudson <treborhudson@gmail.com>

  • attachment app_completion.2.diff added.

Updated patch

02/24/07 12:16:41 changed by Rob Hudson <treborhudson@gmail.com>

I've updated the patch.

  • Support for DJANGO_SETTINGS_MODULE in the environment variable for django-admin.py so you don't have to be in the project directory for this to work.
  • If you are in the project directory, it overrides the environment variable.
  • Changed grep -v django to grep -v django.contrib so app names can contain django. Thanks Paolo.
  • Changed the regular expression to support just 'appname' instead of 'project.appname'. Thanks Paolo.

Thanks for the comments.

02/25/07 10:33:40 changed by jacob

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [4575]) Added completetion support for app names to django_base_completion, which closes #1240. Thanks for the patch, Rob Hudson

02/25/07 14:50:38 changed by amit chakradeo

  • needs_better_patch set to 1.

This completion does not work when django-admin.py or manage.py is not invoked directly. i.e. if you type python django-admin.py and <tab> it does not work. It will be good to have that added as well. I will check and see if I can check the bash manual and add it myself...

--Amit Chakradeo

02/25/07 15:38:24 changed by paolo@php3.it

  • status changed from closed to reopened.
  • resolution deleted.

Amit would please check if my patch work for you?

02/25/07 15:40:45 changed by paolo <paolo@php3.it>

  • attachment a_better_app_completion.diff added.

A patch to improve application name completion

02/25/07 19:37:42 changed by anonymous

paolo, your patch seems to work fine for me in my setup. Would it be easy to also include minor python changes like python2.3 python2.4 as well (in addition to python) ?

--Amit

02/25/07 21:23:46 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Ready for checkin to Accepted.

since being reopened, this is not ready for checkin yet.

02/26/07 11:07:07 changed by paolo <paolo@php3.it>

The new patch support_for_multiple_interpreters.diff should satisfy your request Amit, would you please confirm this? Thanks.

02/26/07 11:08:56 changed by paolo <paolo@php3.it>

  • attachment support_for_multiple_interpreters.diff added.

Updated patch against the trunk

02/26/07 11:20:03 changed by Rob Hudson <treborhudson@gmail.com>

On Mac I get this an error with "whereis". It apparently doesn't take a "-b" flag...

whereis: illegal option -- b usage: whereis program ...

02/26/07 11:40:13 changed by paolo <paolo@php3.it>

Ouch... To be honest I must say I had a weird experience using the -b flag; the man page says that its purpose is to force a search for binaries, and it would be perfect in this case, even if on my system it spits out things like /usr/local/lib/python2.3 and /usr/local/lib/python2.4. That wasn't a problem, as the script is able to handle this situation in some way (the result of basename /usr/local/lib/python2.3 and basename /usr/local/bin/python2.3 is the same), so I decided to leave it.

It becomes a problem if this flag origins an error :-)

Could you please test the patch removing the offending flag? Thanks.

02/26/07 12:15:36 changed by Rob Hudson <treborhudson@gmail.com>

Removing the "-b" doesn't give me an error now, but it doesn't appear to work.

If I'm in a Django project directory, and type: python manage.py [tab][tab], I get a list of all files in the directory rather than a list of options or args. Similarly, typing: python /path/to/django-admin.py [tab][tab], gives me the directory listing. Am I testing this wrong?

-Rob

02/27/07 02:12:12 changed by paolo <paolo@php3.it>

Rob, for me it is working (with and without "-b"). I can use with success "python manage.py [tab][tab]", "python2.3 manage.py [tab][tab]", "/usr/local/bin/python2.3 /usr/local/bin/django-admin.py" and other combinations inside a project.

The only thing I have done is to apply support_for_multiple_interpreters.diff to the bash completion script in the trunk.

I'm using the script both with an old bash version (2.05) and with the recent bash version shipped with Ubuntu Edgy, and it works, so I can't even try to do some investigation, sorry.

02/27/07 11:36:06 changed by Rob Hudson <treborhudson@gmail.com>

My apologies... Something was mixed up in my shell, or I didn't source the profile but it's working this morning. App completion is working as well. Nice!

02/27/07 11:45:57 changed by paolo <paolo@php3.it>

  • needs_better_patch deleted.
  • stage changed from Accepted to Ready for checkin.

Good, thanks for testing!

02/28/07 09:39:54 changed by jacob

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [4646]) Fixed #1240: added better support for different names for "python" to django_bash_completion. Thanks, paolo.

02/28/07 12:57:39 changed by Rob Hudson <treborhudson@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

Actually, this should be re-opened to remove the "-b" option to whereis which breaks on Mac. Paolo, can you update the patch?

02/28/07 17:38:05 changed by paolo@php3.it

Of course, sorry :-(

02/28/07 17:39:12 changed by paolo@php3.it

  • attachment support_for_multiple_interpreters_mac.diff added.

03/07/07 21:34:05 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [4677]) Fixed #1240 -- Fixed portability problem in bash completion script. Thanks, Paolo.

07/08/08 22:46:08 changed by Wonlay

  • cc changed from paolo@php3.it, treborhudson@gmail.com to paolo@php3.it, treborhudson@gmail.com, wonlay@gmail.com.

Does anyone here use tab indent instead of spaces? Tab completion fails if the settings.py is using tab for indent. I will upload a working patch for this.

07/08/08 22:48:21 changed by Wonlay

  • attachment django_bash_completion.diff added.

Fix problems when tabs are used for indent of settings.py


Add/Change #1240 (Tab-completion actions for django-admin)




Change Properties
Action