8

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 http://gb.archive.ubuntu.com/ubuntu/ vivid/main amd64 Packages
        100 /var/lib/dpkg/status
1
  • This is a good question. I love the idea behind it. I have been looking all over, and I have found some close answers, but they fail when I try them. If I come up with something, I will let you know. =)
    – Terrance
    Jul 26, 2015 at 4:07

2 Answers 2

5

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.

0

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 https://github.com/zsh-users/antigen.git

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
  • Ah, that only works for me if I do exactly as you did, otherwise it just assumes that I am running cd and does the file path thing. How do I get it to read the .bash_aliases file?
    – user364819
    Jul 26, 2015 at 11:58
  • I attempted to install those plugins, but I just got antigen: command not found on configuration.
    – user364819
    Jul 26, 2015 at 12:43

You must log in to answer this question.