May 24, 2009

Bash completion with aptitude aliases

Problem:

  1.    If I used my alias for installing an application (inst application), I would have to know the full application name because I would not have bash completion.  This was very annoying when installing libraries because they often have weird version strings tacked on to their ends.
  2.    If I used the full command (sudo aptitude install application), I would have bash completion and would therefore not have to know the whole application name. I could simply type libxul and get libxul0d.

On one hand, I would type a short command plus a complected application name, on the other I would type a long command and a simple application name.  I wanted to be able to type a short command with a simple application name.


Solution:

   I wrote my own bash completion rules.  They are based on the default aptitude bash completion rules but customized for aliases. Here is the text http://paste2.org/p/223473. Just copy it into a file such as ~/.bash_completion and source the file in your ~/.bashrc by adding ". ~/.bash_completion".

  Change/Add/Remove the aliases at the end of the file. The lines that start with complete -F _aptitude_all complete any available or installed package and lines that start with complete -F _aptitude_installed complete only installed packages.

  inst, upgrade, apt-info, apt-changes.... are my aliases. You must use YOUR ALIASES for this to work. To add aliases, read this.

0 comments:

Post a Comment