Code

Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#1240 closed enhancement (fixed)

Tab-completion actions for django-admin

Reported by: paolo <paolo@…> Owned by: adrian
Component: Core (Management commands) Version: master
Severity: minor Keywords:
Cc: paolo@…, treborhudson@…, wonlay@…, gonz Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (10)

django (3.2 KB) - added by paolo <paolo@…> 8 years ago.
django.2 (3.2 KB) - added by paolo <paolo@…> 8 years ago.
Django bash completion script updated for 0.95 (post-magic-removal)
django.3 (3.9 KB) - added by paolo <paolo@…> 8 years ago.
Django bash completion script updated to reflect changes happened in #1736
appname-completion.diff (1.5 KB) - added by scott@… 8 years ago.
[patch] appname completion
app_completion.diff (889 bytes) - added by Rob Hudson <treborhudson@…> 7 years ago.
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@…> 7 years ago.
Updated patch
a_better_app_completion.diff (790 bytes) - added by paolo <paolo@…> 7 years ago.
A patch to improve application name completion
support_for_multiple_interpreters.diff (1.6 KB) - added by paolo <paolo@…> 7 years ago.
Updated patch against the trunk
support_for_multiple_interpreters_mac.diff (531 bytes) - added by paolo@… 7 years ago.
django_bash_completion.diff (657 bytes) - added by Wonlay 6 years ago.
Fix problems when tabs are used for indent of settings.py

Download all attachments as: .zip

Change History (47)

Changed 8 years ago by paolo <paolo@…>

comment:1 Changed 8 years ago 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

comment:2 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

Changed 8 years ago by paolo <paolo@…>

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

comment:3 Changed 8 years ago by paolo <paolo@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:4 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Changed 8 years ago by paolo <paolo@…>

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

comment:5 Changed 8 years ago by anonymous

  • Cc paolo@… added
  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:6 Changed 8 years ago 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. :-)

comment:7 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Changed 8 years ago by scott@…

[patch] appname completion

comment:8 Changed 8 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

[patch] appname completion

comment:9 Changed 8 years ago by hi-world cup

  • Cc hi-world, cup added; paolo@… removed
  • Keywords rthml tab space editor js added
  • Summary changed from Tab-completion actions for django-admin to hi-world cup

comment:10 Changed 8 years ago by adrian

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

comment:11 Changed 8 years ago by paolo

  • Cc paolo@… added; hi-world, cup removed
  • Keywords rthml tab space editor js removed

comment:12 Changed 8 years ago by anonymous

  • Component changed from django-admin.py to Generic views
  • milestone set to Version 0.92
  • priority changed from normal to high
  • Severity changed from minor to normal
  • Type changed from enhancement to task
  • Version set to magic-removal

comment:13 Changed 8 years ago by paolo <paolo@…>

  • Component changed from Generic views to django-admin.py
  • milestone Version 0.92 deleted
  • priority changed from high to normal
  • Severity changed from normal to minor
  • Type changed from task to enhancement
  • Version changed from magic-removal to SVN

comment:14 Changed 8 years ago by adrian

  • Resolution set to invalid
  • Status changed from reopened to closed

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

comment:15 Changed 7 years ago by afternoon@…

  • Keywords http status response added

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

comment:16 Changed 7 years ago by Rob Hudson <treborhudson@…>

  • Cc treborhudson@… added
  • Has patch set
  • Keywords http status response removed
  • Resolution invalid deleted
  • Status changed from closed to reopened

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/#

Changed 7 years ago by Rob Hudson <treborhudson@…>

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

comment:17 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:18 Changed 7 years ago by afternoon@…

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.

Changed 7 years ago by Rob Hudson <treborhudson@…>

Updated patch

comment:19 Changed 7 years ago by Rob Hudson <treborhudson@…>

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.

comment:20 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:21 Changed 7 years ago by amit chakradeo

  • Patch needs improvement set

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

comment:22 Changed 7 years ago by paolo@…

  • Resolution fixed deleted
  • Status changed from closed to reopened

Amit would please check if my patch work for you?

Changed 7 years ago by paolo <paolo@…>

A patch to improve application name completion

comment:23 Changed 7 years ago 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

comment:24 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Ready for checkin to Accepted

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

comment:25 Changed 7 years ago by paolo <paolo@…>

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

Changed 7 years ago by paolo <paolo@…>

Updated patch against the trunk

comment:26 Changed 7 years ago by Rob Hudson <treborhudson@…>

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

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

comment:27 Changed 7 years ago by paolo <paolo@…>

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.

comment:28 Changed 7 years ago by Rob Hudson <treborhudson@…>

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

comment:29 Changed 7 years ago by paolo <paolo@…>

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.

comment:30 Changed 7 years ago by Rob Hudson <treborhudson@…>

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!

comment:31 Changed 7 years ago by paolo <paolo@…>

  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

Good, thanks for testing!

comment:32 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:33 Changed 7 years ago by Rob Hudson <treborhudson@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:34 Changed 7 years ago by paolo@…

Of course, sorry :-(

Changed 7 years ago by paolo@…

comment:35 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:36 Changed 6 years ago by Wonlay

  • Cc wonlay@… added

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.

Changed 6 years ago by Wonlay

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

comment:37 Changed 5 years ago by gonz

  • Cc gonz added

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.