Skip to content

Command shortcut aliases #81

@shangxiao

Description

@shangxiao

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

Add shortcuts to common commands:

  • mm for makemigrations
  • sm for showmigrations
  • m for migrate
  • rs for runserver

Problem

For folks who work mostly from terminals, forming shortcuts to everyday tasks is often regarded as essential for productivity & sanity, relieving you from tedium.

Eg having to type out ./manage.py showmigrations <app-name> can start to be a drag.

Note It's extremely simple to setup (see below); am adding this request in case folks wish to see this added to core 🤷‍♂️ If you want to vote no because of its simplicity then that's a good reason 👍

Note Note Tab completion of commands has existed for some time now but I've not had a good experience with it. I've personally found it to be not fast enough for it to be productive. Additionaly tab completion needs to have an unambiguous prefix to wholly complete. Compare this with the speed of typing mm.

Request or proposal

request

Additional Details

It's actually extremely simple to setup your own shortcuts and I've started setting this up on most projects I start working on: https://github.com/shangxiao/stupid-django-tricks/tree/master/management_command_alias

In manage.py

def alias_map(argv):
    if len(argv) > 1:
        argv[1:2] = settings.COMMAND_ALIASES.get(argv[1], argv[1]).split(" ")
    return argv

if __name__ == "__main__":
    execute_from_command_line(alias_map(sys.argv))

In your settings:

COMMAND_ALIASES = {
    "mm": "makemigrations --no-header",
    "sp": "shell_plus",
    # ... etc ...
}

Aliasing manage.py

Though this is possibly outside the scope of this request (though I think as part of Django would make other folks' lives easier), I shell alias ./manage.py with dj so my daily routine becomes effortless:

$ dj sm app<tab-completion>
$ dj mm
$ dj m
 ... etc ...

Implementation Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions