Get auto-completion back in bash
[ Main_Page ]
Contents
Autocompletion! why?
Autocompletion allows you save a lot of typing and typos while entering text in the terminal. After typing few letters of a command or variable name, just use Tab ↹ and the system will fill the remaining when it is unique or propose you alternatives to select from. When several choices are proposed, add enough new letters to make your query 'more' unique and hit Tab ↹ again.
Unfortunately, the most recent version of bash (4.2) introduced a bug that broke the autocomplete process.
Luckily, there are few things you can do to restore auto-completion until it gets fixed in a new bash version and they are detailed here.
Install and execute git-autocompletion.bash
A script has been developed by a number of people and can be obtained from the following URL [1]. Download the script to your home folder and rename it with a leading dot to make it invisible (this prevents seeing it when you list the folder and deleting it by mistake.
- navigate to [1] and save the page as text
- rename and move to your home folder
- execute the modified version of your config file
# move the file after downloading it mv ~/Downloads/git-completion.bash ~/.git-completion.bash # add few lines to your .bashrc echo '# source git completion script # https://github.com/git/git/blob/master/contrib/completion/git-completion.bash if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi' >> ~/.bashrc # execute the modified version of your config file source ~/.bashrc
Bash auto complete for environment variables
If you search for this, you will find numbers of pages including this[2]. Two solutions are proposed.
add direxpand to your .bashrc
The first one is best if it works and involves running the shopt -s direxpand command (and adding it to your .bashrc). This worked under Mint16.
shopt -s direxpand # add a line to your .bashrc echo '# add back variable expansion shopt -s direxpand' >> ~/.bashrc
use control keys while typing
The second solution is reproduced from[3]
The workaround suggested in http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00274.html is:
- use Tab ↹ to auto-complete your environment variable s.t. you command line says cd $MYVAR
- hit ⎋ Esc+⎈ Ctrl-E to expand the current command line i.e. substitute $MYVAR by its value, the path
- add a /
- enjoy Tab ↹ auto-completion as usual
This assumes you are in emacs mode (set -o emacs) and have bash_completion set up sensibly for cd (e.g. complete -o nospace -F _cd cd).
Unfortunately this doesn't work in vi mode (set -o vi) because command line expansion is not available then.
References:
- ↑ https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
- ↑ http://askubuntu.com/a/54892
- ↑ http://askubuntu.com/questions/41891/bash-auto-complete-for-environment-variables
[ Main_Page ]