Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.