Yeah! It's already the 4th zoom of your Quickly trip and it's about shell completion.

Complete everything quickly

Quickly has an advanced shell completion tool. Currently, it's only binded to bash but plans are up to catch other shells (it's very easy, just call quickly shell-completion $0 from a script and perform little black magic to know the context).

You can reread part 2 if you want to understand every cases described below. Ensure as well you have Quickly 0.2.3.

After installation

Once Quickly is set up, you have to launch a new bash to get the bash completion working. This hasn't some workaround and it's the same with other tool (bzr, quilt...)

Ok, let's try a basic example:

Outside any project

quickly [Tab][Tab]
awesome commands    create      getstarted  help        quickly     tutorial

-> We get there all builtin and template commands which can be launched outside a project.

Here, commands, getstarted, help and quickly are builtin commands. Create and tutorial are ubuntu-project template commands.

Now, let's try a basic builtin command:
$ quickly commands [Tab][Tab]
<file list of my current folder>

Ok, that means that we have no parameter to specify or that the commands command don't support more advanced completion.

Testing a template command which can be launched outside a project:
$ quickly tutorial [Tab][Tab]
footemplate               ubuntu-project

This is because the tutorial command is (in my personal installation) present in two templates, so as this command can be launched outside a template, you need to specify a template.

Then, picking one template:

$ quickly tutorial ubuntu-project [Tab][Tab]
<file list of my current folder>

That means that tutorial command doesn't have advanced shell completion either

Note that you can also do:

$ quickly --template ubuntu-project tutorial [Tab][Tab]
<file list of my current folder>

This time, as you have already defined a template, Quickly Core won't bother you to propose a template after the tutorial command.

Advanced!

You should understand why this doesn't display more commands:

quickly -t ubuntu-project [Tab][Tab]
commands    create      getstarted  help        quickly     tutorial

What's the difference with the first example? There is no awesome command[1]! It only lists builtin and ubuntu-project commands that can be launched outside a project. So, awesome command is certainly from another template than ubuntu-project in this case.

Inside a project

Common case

Let's give it a try:

$ quickly [Tab][Tab]
change-lp-project  getstarted         package            save
commands           glade              quickly            share
dialog             help               release            tutorial
edit               license            run

The list is made from builtin and associated template (here ubuntu-project template) command that can be launched inside the project (for instance, the create command is not listed).

From another template

As for help and launching a command, I can see commands from others templates, being in the same directory, that I can launch:

$ quickly -t footemplate [Tab][Tab]
commandfoo  getstarted  package     run
commands    help        quickly     tutorial

Here, I get builtin and footemplate commands that I can launch inside a project. Easy!

Advanced completion

As previously said, some commands can have advanced completion.

Command defined

They can defined it themselves (apart from the template part and command which is automatically handled by Quickly Core).

For instance, the license command from ubuntu-project defines an advanced (optional) parameters which is the license, Using shell-completion enable to discover every available licenses supported by ubuntu-project template:

Inside a project:

$ quickly license [Tab][Tab]
BSD     GPL-2   GPL-3   LGPL-2  LGPL-3

Command followed by command (headaches inside)

Do you remember part 2? I discussed about attributes on commands and we see before command followed by templates. There are also commands followed by another command. As of today, only the help builtin command has this attribute. But remember: help command is also a command followed by a template. Seems to be an interested case for testing shell completion behavior, isn't?

Outside a project
$ quickly help [Tab][Tab]
commands        help            toto
getstarted      quickly         ubuntu-project

help completion propose you with what you can get some help:

  • directly builtin commands which can be launched outside any project
  • available templates (for later completion)
$ quickly help ubuntu-project [Tab][Tab]
change-lp-project  edit               license            run
commands           getstarted         package            save
create             glade              quickly            share
dialog             help               release            tutorial

Here you get help on all builtins and commands from ubuntu-project template (as see in previous part for the help command)!

For bonus point:

$ quickly -t ubuntu-project help [Tab][Tab]
change-lp-project  edit               license            run
commands           getstarted         package            save
create             glade              quickly            share
dialog             help               release            tutorial

Same thing than previously, but using the -t option.

Inside a project

In this cas, help command completion will behave as expected after reading last chapter:

$ quickly help [Tab][Tab]
change-lp-project  edit               license            run
commands           getstarted         package            save
create             glade              quickly            share
dialog             help               release            tutorial

You have there all builtins and ubuntu-project template commands (given the fact that you are in a ubuntu-project "templated" project).

Bonus, for people who likes to complicate their life:

$ quickly -t footemplate help [Tab][Tab]
awesome     commands    getstarted  package     run
commandfoo  create      help        quickly     tutorial

Here, you are in a ubuntu-project "templated" project and you get help on all builtins commands and those from footemplate.

Miscellaneous

Option completion

Option benefit of course from completion:

$ quickly -[Tab][Tab]
-h          --help      --staging   -t          --template  --verbose   --version
Template completion

In addition to previous case of template completion, the -t/---template command has its own completion!

$ quickly --template [Tab][Tab]
footemplate               ubuntu-project

Good news is all of that is generically implemented in the Quickly Core itself. So, if you plan to create a Quickly template, you can get it also for free if you put right attributes to your personal commands (we will see that in a chapter 6).

Hope you will like this advanced completion setting (it gave me quite some headaches and a lot of trial/refactoring phases before getting it generically working and the code not being too ugly). Remember again that we will see how command can add to this completion their own level, as for help. :)

In next part, we will see miscellaneous things on the Quickly core itself.

Notes

[1] this does not imply that the listed command aren't awesome ;)