6

I have a whole bunch of aliased commands in .bash_aliases

The most generic examples are

alias apt-update="sudo apt-get update"  
alias apt-upgrade="sudo apt-get dist-upgrade"

but then I also have

alias apt-install="sudo apt-get install "
alias a2avail="/etc/apache2/sites-available"

The first two are no issue, The second two I want to make the more powerful;

Specifically for apt-install I want autocomplete to work.

for a2avail I want to be able to type something like sudo cp a2avail/default a2avail/new and have it run as sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/new

are either of these two things possible?

1

2 Answers 2

6

Adding the following to your ~/.bashrc should complete packagenames for your apt-install alias

_apt_install_complete() { 
    mapfile -t COMPREPLY < <(apt-cache --no-generate pkgnames "$2");
}
complete -F _apt_install_complete apt-install

As for a2avail, an alias will only work as the first word of a command, but you can use a variable.

a2avail=/etc/apache2/sites-available   # in ~/.bashrc

# then...
sudo cp "$a2avail"/{default,new}
0

As of July 4th, 2017:

  1. Install complete-alias.

  2. Add this line: complete -F _complete_alias apt-install.

You are done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .