Use TAB key complete feature in Linux Bash console
One of the best features of Django CMS is to have a wide set of commands to manage your web application from console.
One of the things that Linux users miss when working with a clean instance of Django is the ability of pressing the TAB key while writing a command to autocomplete them or presing TAB key twice to see all the available options.
In this tutorial we will enable such feature.
Bash completion feature works by having a special script that uses the three builtin commands that are available to manipulate the programmable completion facilities, they are:
For each program, there should be a script that uses them to properly enable the autocompletion feature, in Django this file is located in a special directory in main repository, not included in the delivered project by default, it is located at: https://github.com/django/django/master/extras/django_bash_completion
We first start by downloading this file into
~/local/share/django/extras directory, so in this case
~/local/share/django/extras would create the needed path.
Then downloading it and posting in the above directory wget -O ~/local/share/django/extras/django_bash_completion.sh https://raw.github.com/django/django/master/extras/django_bash_completion.
$ mkdir -p ~/local/share/django/extras $ wget -O ~/django_bash_completion.sh https://raw.github.com/django/django/master/extras/django_bash_completion --2019-01-29 18:10:52-- https://raw.github.com/django/django/master/extras/django_bash_completion Resolving raw.github.com (raw.github.com)... 126.96.36.199 Connecting to raw.github.com (raw.github.com)|188.8.131.52|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://raw.githubusercontent.com/django/django/master/extras/django_bash_completion [following] --2019-01-29 18:10:53-- https://raw.githubusercontent.com/django/django/master/extras/django_bash_completion Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 184.108.40.206 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2332 (2,3K) [text/plain] Saving to: ‘/home/marcanuy/django_bash_completion.sh’ /home/marcanuy/django_bash_completion 100%[======================================================================>] 2,28K --.-KB/s in 0s 2019-01-29 18:10:53 (10,4 MB/s) - ‘/home/marcanuy/django_bash_completion.sh’ saved [2332/2332]
2. Sourcing the file
Now we need to source the downloaded script, so the autocompletion is loaded into our console.
To make it available in our console we just run source ~/local/share/django/extras/django_bash_completion.sh.
But there is a good chance that there is a virtual environment for each project, so depending in what type of virtual environment you are using you can load it at different places:
If you load your virtual environment manually, e.g.:
~/.virtualenvs/MY-PROJECT/bin/activate, with a simple script in you
project root like
#!/bin/bash source ~/.virtualenvs/MY-PROJECT/bin/activate source ~/local/share/django/extras/django_bash_completion.sh
And then load your virtual environment by executing source activate.sh
2.2. Using virtualenvwrapper
For virtualenvwrapper, add
~/local/share/django/extras/django_bash_completion.sh in the
After doing this simple installation, each type we press the TAB key while executing a command with python manage.py TAB it will load the list of available commands or autocomplete accordingly.
- Django Overview
- Django Configuration and environment isolation
- Have multiple submit buttons for the same Django form
- Better Testing with Page Object Design in Django
- Generating slugs automatically in Django without packages - Two easy and solid approaches
- How to set up Django tests to use a free PostgreSQL database in Heroku
- Dynamically adding forms to a Django FormSet with an add button using jQuery
- Use of Django's static templatetag in css file to set a background image
- Activate Django's manage.py commands completion in Bash in 2 steps
- Sending Emails with Django using SendGrid in 3 easy steps
- Adding Users to Your Django Project With A Custom User Model
- Setting Up A Factory For One To Many Relationships In Factoryboy
- Generate UML class diagrams from django models
- Set Up Ubuntu To Serve A Django Website Step By Step
- Django Project Directory Structure
- Adding a Cancel button in Django class-based views, editing views and forms
- Using Django Model Primary Key in Custom Forms THE RIGHT WAY
- Django formset handling with class based views, custom errors and validation
- How To Use Bootstrap 4 In Django Forms
- Understanding Django Forms
- How To Create A Form In Django