Celeb Glow
updates | March 23, 2026

How to get [TAB] to work with arguments of aliases to autocomplete as can be done with the actual command

I have many aliases that I created in my .bash_aliases file, and they are very useful, so if I want all info on a package I do something like:

allinfo software-center

And that does the equivalent of:

apt-cache show software-center

As the alias is set as:

alias allinfo='apt-cache show'

But there is one disadvantage of this, I am currently unable to autocomplete with TAB when using allinfo instead of the actual command. So I was wondering if there was a way to overcome this disadvantage and make it so that doing allinfo software-ce[TAB] will work just the same as it does when you use it with the actual command, and not just make a large tab space?

I am using gnome-terminal.


OS Information:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 15.04
Release: 15.04
Codename: vivid

Package Information:

gnome-terminal: Installed: 3.14.2-0ubuntu3 Candidate: 3.14.2-0ubuntu3 Version table: *** 3.14.2-0ubuntu3 0 500 vivid/main amd64 Packages 100 /var/lib/dpkg/status
1

2 Answers

Great question! If your allinfo command was the same as just apt-cache, (ie, without the show) then we could look at the completion for apt-cache, and apply that to your allinfo alias.

However, you want a subset of the apt-cache completion, so we have a little more work to do.

If we look in the completion definition for apt-cache - in /usr/share/bash-completion/completions/apt-cache, we see the following is used for the show subcommand:

 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" 2> /dev/null ) )

- this is just setting the COMPREPLY variable to the list of matching packages.

So, we can borrow this and write our own function, and bind it to your allinfo alias:

# define a function to print the possible completions for
# an allinfo invocation
_allinfo()
{ _init_completion || return COMPREPLY=($(apt-cache --no-generate pkgnames "$cur" 2>/dev/null)) return 0
}
# bind the above completion function to the 'allinfo' alias
complete -F _allinfo allinfo

If you add that fragement to your .bashrc file, you should get the completions working as you expect.

I have no idea for bash, but it works with zsh and some plugins

Install the z-shell with

sudo apt-get install zsh

and set the z-shell as your standard shell

sudo chsh "$USER" -s $(which zsh)

and start a new terminal to use the z-shell

Add Antigenv1

cd
git clone 

And configure

# path to antigen clone
source ~/antigen/antigen.zsh
# Load the oh-my-zsh's library.
antigen use oh-my-zsh
# Bundles from the default repo (robbyrussell's oh-my-zsh).
antigen bundle git
antigen bundle heroku
antigen bundle pip
antigen bundle lein
antigen bundle command-not-found
antigen bundle zsh-users/zsh-completions src
# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting
# Load the theme.
antigen theme robbyrussell
# antigen bundle nojhan/liquidprompt
# Tell antigen that you're done.
antigen apply

Some images (prompt is nojhan/liquidprompt)

enter image description here

enter image description here

enter image description here

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy