TAB-Completion

Bash tab-completion
By default Bash will complete filenames if you press the tab key. This is useful and saves typing but doesn't take into account context. For example the first argument to the chown command is a username not a file.

Following the steps below will give you enhanced completion, taking context into account such as this partial list of examples:
 * Commands which only take directories (eg cd get only those)
 * Document types (eg PDF readers complete to pdf files)
 * Usernames and groups are supplied where appropriate (eg chown and chgrp)
 * Process ids (eg kill), devices (eg mount), man pages (eg man) are supplied as appropriate
 * Command line options (eg type chown - and hit tab)
 * Command line options are taken into account. eg if you press tab after find -uid you get a list of userids and after find -fstype you get a list of file system types.
 * You can write your own completions (see /etc/bash_completion and /etc/bash_completion.d for how the existing ones are implemented)

Installation
First, edit and add the  USE flag or add it to every package you want completion for. These need to be recompiled of course.

Then, install :

Now add the following line to, before setting any alias (see bug #338335):

Configuration
There are two tools for configuring bash-completion: eselect and bash-completion-config. If you have installed a package with a bash-completion USE flag, it is likely you already have eselect. If you don't, install it:

Eselect can manage a lot more than just bash-completion, so it is recommended you use it. If you don't want to or can't, there's also bash-completion-config.

Portage-related commands
By default, Bash tab-completion support for Portage related commands (emerge, equery, revdep-rebuild etc.) is globally enabled, but usually only the root user can use them. Unless other users are part of the portage group, enter the following commands:


 * if using eselect:


 * if using bash-completion-config:

At last, log out and in again or.

Other commands
Only Bash tab-completion support for the Portage-related commands is enabled by default, but as previously said other tools (unrar, genlop etc.; here is the full list) support this nice feature as well.

If you want to enable Bash tab-completion for the genlop command, for example, just type:


 * if using eselect:


 * if using bash-completion-config:

If you want to enable all Bash tab-completions available for your system, type:


 * (perform this for each user)

Remember, for the changes to have an immediate effect, issue the following command:

Customizations

 * Activate Bash completion with one TAB key press instead of two TAB key presses.

If you are creating your file, you may find this breaks your  and  keys. If you find this happens, you may like to add this:

If you want to make completion case insensitive (useful for tabbing through upper-case filesystem objects):

Known bugs
Bug: Problem with disabling a module in bash-completion. For details, see bug report #133765

Zsh tab-completion
If you want to enable Portage related commands completion, install :

Now add the following lines to your :

Also, if you want to enable cache for the completions, add to your :

Testing
Let's check if everything went well. Without pressing the return key, type. Now press the tab key. You should obtain: