Opened 11 years ago

Closed 10 years ago

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

Download all attachments as: .zip

Change History (47)

Changed 11 years ago by paolo <paolo@…>

Attachment: django added

comment:1 Changed 11 years ago by apgwoz (aaaaat) gmail (tod) com

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 Changed 10 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

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

Changed 10 years ago by paolo <paolo@…>

Attachment: django.2 added

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

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

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 Changed 10 years ago by Adrian Holovaty

Resolution: fixed
Status: reopenedclosed

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

Changed 10 years ago by paolo <paolo@…>

Attachment: django.3 added

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

comment:5 Changed 10 years ago by anonymous

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

comment:6 Changed 10 years ago by Malcolm Tredinnick

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

Resolution: fixed
Status: reopenedclosed

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

Changed 10 years ago by scott@…

Attachment: appname-completion.diff added

[patch] appname completion

comment:8 Changed 10 years ago by (none)

Resolution: fixed
Status: closedreopened

[patch] appname completion

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

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 Changed 10 years ago by Adrian Holovaty

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

comment:11 Changed 10 years ago by paolo

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

comment:12 Changed 10 years ago by anonymous

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

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

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

comment:14 Changed 10 years ago by Adrian Holovaty

Resolution: invalid
Status: reopenedclosed

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

comment:15 Changed 10 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 10 years ago by Rob Hudson <treborhudson@…>

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

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

Attachment: app_completion.diff added

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

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

Triage Stage: UnreviewedReady for checkin

comment:18 Changed 10 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 10 years ago by Rob Hudson <treborhudson@…>

Attachment: app_completion.2.diff added

Updated patch

comment:19 Changed 10 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 10 years ago by Jacob

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 Changed 10 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 10 years ago by paolo@…

Resolution: fixed
Status: closedreopened

Amit would please check if my patch work for you?

Changed 10 years ago by paolo <paolo@…>

A patch to improve application name completion

comment:23 Changed 10 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 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: Ready for checkinAccepted

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

comment:25 Changed 10 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 10 years ago by paolo <paolo@…>

Updated patch against the trunk

comment:26 Changed 10 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 10 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 10 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 10 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 10 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 10 years ago by paolo <paolo@…>

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Good, thanks for testing!

comment:32 Changed 10 years ago by Jacob

Resolution: fixed
Status: reopenedclosed

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

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

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 Changed 10 years ago by paolo@…

Of course, sorry :-(

Changed 10 years ago by paolo@…

comment:35 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: reopenedclosed

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

comment:36 Changed 8 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 8 years ago by Wonlay

Attachment: django_bash_completion.diff added

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

comment:37 Changed 7 years ago by Gonzalo Saavedra

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