You are not logged in.

#1 2012-08-24 12:41:15

XZS
Member
Registered: 2011-05-11
Posts: 30

Aliases with _completion_loader

Bash uses a function called _completion_loader to dynamically load completion functions for each program. This works whenever the program is correctly called by its name. So for example, typing 'pacman -Qi s' and hitting Tab offers all installed packages starting with s. Now I alias 'pacman' to 'p' and advise bash to use the pacman completer for p also. This works in the current running shell but fails with a new shell, because the completer was not yet loaded there.

What can be done so that the alias also loads the pacman completion function?

Offline

#2 2012-08-24 13:18:20

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Aliases with _completion_loader

You could add pacman's completion function in your bashrc:

alias p=pacman

if [ -f /usr/share/bash-completion/completions/pacman ]; then 
  . /usr/share/bash-completion/completions/pacman
  complete -F _pacman -o filenames -o default p 
fi

Offline

#3 2012-08-24 14:18:55

XZS
Member
Registered: 2011-05-11
Posts: 30

Re: Aliases with _completion_loader

This would definitely work, but defeats the purpose of dynamic completion loading to begin with.

A symlink from p to pacman in /etc/bash_completion.d/ would solve the problem. But this would affect other users that may have p bound to something else.

Offline

Board footer

Powered by FluxBB