You are not logged in.

#1 2010-05-29 22:41:41

rgb
Member
Registered: 2010-02-11
Posts: 24

Bash aliases auto-completing issue

It is possible to make bash's auto-completion to work with an alias? Like:

alias install="sudo pacman -S"
install firef[TAB]

Offline

#2 2010-05-29 23:33:36

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Bash aliases auto-completing issue

I guess you already installed the bash-completion package and sourced /etc/bash_completion in your .bashrc?

Most of the bash completion abilities are provided by functions. For instance, the completion function for pacman is defined in /etc/bash_completion.d/pacman, which get's included by /etc/bash_completion.

To get the completion for your alias, you have to write a new wrapper function for _available_pkgs (also defined in that file):

_install_pkgs () {
    COMPREPLY=()
    cur=`_get_cword`
    _available_pkgs
}

Finally, you have to tell bash to use that function for your alias:

complete -F _install_pkgs install

Put both in your .bashrc or in /etc/bash_completion or in /etc/bash_completion.d/pacman, considering that the last two might get overwritten by an update.

Offline

#3 2010-05-30 00:42:25

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: Bash aliases auto-completing issue

you could also use zsh instead of bash which, iirc, comes with alias and pacman (command and package name) completion preconfigured.
Of course it has many other perks.


no place like /home
github

Offline

Board footer

Powered by FluxBB