Gentoo Wiki ArchivesGentoo Wiki

TIP_TAB-completion

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

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:

Installation

First, edit /etc/make.conf and add the bash-completion USE flag. Every package on your system supporting this USE flag - not compiled with this USE flag, should now be recompiled:

# emerge -avuN world

Then, install bash-completion:

# emerge -av bash-completion gentoo-bashcomp

Now add the following line to /etc/bash/bashrc, before setting any alias (see bug #98627):

File: /etc/bash/bashrc
[[ -f /etc/profile.d/bash-completion ]] && source /etc/profile.d/bash-completion

Let the changes take effect:

# source /etc/bash/bashrc

Or exit the shell and login again.

Configuration

There are two tools for configuring bash-completion: eselect and bash-completion-config. Choose one of them and install it:

# emerge -av eselect

or

# emerge -av 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:

# eselect bashcomp disable --global gentoo
# eselect bashcomp enable gentoo
# bash-completion-config --uninstall --global gentoo
# bash-completion-config --install gentoo

At last:

# source /etc/bash/bashrc

Other commands

Only Bash tab-completion support for the Portage-related commands is enabled by default, but as we 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:

# eselect bashcomp enable genlop
# bash-completion-config --install genlop 

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

# source /etc/bash/bashrc

Enabling All Completions

If you want to enable all of the installed completions you can run this command:

# for i in $(ls --color=no /usr/share/bash-completion/); do ln -s /usr/share/bash-completion/$i ~/.bash_completion.d/$i; done

Or, if you want to enable all installed completions globally, run this as root:

# for i in $(ls --color=no /usr/share/bash-completion/); do ln -s /usr/share/bash-completion/$i /etc/bash_completion.d/$i; done

Customizations

File: ~/.inputrc
 set show-all-if-ambiguous On
$ bash -$-

If you are creating your ~/.inputrc file, you may find this breaks your Home and End keys. If you find this happens, you may like to add this:

File: ~/.inputrc
 "\e[1~": beginning-of-line
 "\e[4~": end-of-line 

Known Bugs

Bug: Problem at disabling a module in bash-completion
For details, see bug report #133765

Zsh Completion

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

# emerge -av zsh-completion

Now add the following lines to your ~/.zshrc:

File: ~/.zshrc
 autoload -U compinit promptinit
 compinit
 promptinit; prompt gentoo

Also, if you want to enable cache for the completions, add to your ~/.zshrc:

File: ~/.zshrc
zstyle ':completion::complete:*' use-cache 1


Testing

Let's check if everything went well. Without pressing the return key, type:

# emerge rkh

Now press the tab key. You should obtain:

# emerge rkhunter

Wonderful, isn't it? ;)

Retrieved from "http://www.gentoo-wiki.info/TIP_TAB-completion"

Last modified: Sat, 27 Sep 2008 20:21:00 +1000 Hits: 52,625

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.