Opened 19 years ago

Closed 18 years ago

Last modified 16 years ago

#1240 closed enhancement (fixed)

Tab-completion actions for django-admin

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

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

Download all attachments as: .zip

Change History (47)

by paolo <paolo@…>, 19 years ago

Attachment: django added

comment:1 by apgwoz (aaaaat) gmail (tod) com, 19 years ago

Severity: normalminor

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 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

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

by paolo <paolo@…>, 18 years ago

Attachment: django.2 added

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

comment:3 by paolo <paolo@…>, 18 years ago

Resolution: fixed
Status: closedreopened

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 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

by paolo <paolo@…>, 18 years ago

Attachment: django.3 added

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

comment:5 by anonymous, 18 years ago

Cc: paolo@… added
Resolution: fixed
Status: closedreopened

comment:6 by Malcolm Tredinnick, 18 years ago

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 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

by scott@…, 18 years ago

Attachment: appname-completion.diff added

[patch] appname completion

comment:8 by (none), 18 years ago

Resolution: fixed
Status: closedreopened

[patch] appname completion

comment:9 by hi-world cup, 18 years ago

Cc: hi-world cup added; paolo@… removed
Keywords: rthml tab space editor js added
Summary: Tab-completion actions for django-adminhi-world cup

comment:10 by Adrian Holovaty, 18 years ago

Summary: hi-world cupTab-completion actions for django-admin

comment:11 by paolo, 18 years ago

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

comment:12 by anonymous, 18 years ago

Component: django-admin.pyGeneric views
milestone: Version 0.92
priority: normalhigh
Severity: minornormal
Type: enhancementtask
Version: magic-removal

comment:13 by paolo <paolo@…>, 18 years ago

Component: Generic viewsdjango-admin.py
milestone: Version 0.92
priority: highnormal
Severity: normalminor
Type: taskenhancement
Version: magic-removalSVN

comment:14 by Adrian Holovaty, 18 years ago

Resolution: invalid
Status: reopenedclosed

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

comment:15 by afternoon@…, 18 years ago

Keywords: http status response added

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

comment:16 by Rob Hudson <treborhudson@…>, 18 years ago

Cc: treborhudson@… added
Has patch: set
Keywords: http status response removed
Resolution: invalid
Status: closedreopened

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

by Rob Hudson <treborhudson@…>, 18 years ago

Attachment: app_completion.diff added

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

comment:17 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedReady for checkin

comment:18 by afternoon@…, 18 years ago

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.

by Rob Hudson <treborhudson@…>, 18 years ago

Attachment: app_completion.2.diff added

Updated patch

comment:19 by Rob Hudson <treborhudson@…>, 18 years ago

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 by Jacob, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

comment:21 by amit chakradeo, 18 years ago

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 by paolo@…, 18 years ago

Resolution: fixed
Status: closedreopened

Amit would please check if my patch work for you?

by paolo <paolo@…>, 18 years ago

A patch to improve application name completion

comment:23 by anonymous, 18 years ago

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 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: Ready for checkinAccepted

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

comment:25 by paolo <paolo@…>, 18 years ago

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

by paolo <paolo@…>, 18 years ago

Updated patch against the trunk

comment:26 by Rob Hudson <treborhudson@…>, 18 years ago

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 by paolo <paolo@…>, 18 years ago

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 by Rob Hudson <treborhudson@…>, 18 years ago

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 by paolo <paolo@…>, 18 years ago

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 by Rob Hudson <treborhudson@…>, 18 years ago

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 by paolo <paolo@…>, 18 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Good, thanks for testing!

comment:32 by Jacob, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

comment:33 by Rob Hudson <treborhudson@…>, 18 years ago

Resolution: fixed
Status: closedreopened

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 by paolo@…, 18 years ago

Of course, sorry :-(

comment:35 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

comment:36 by Wonlay, 16 years ago

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.

by Wonlay, 16 years ago

Attachment: django_bash_completion.diff added

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

comment:37 by Gonzalo Saavedra, 16 years ago

Cc: Gonzalo Saavedra added
Note: See TracTickets for help on using tickets.
Back to Top