Getting Started with Completion

There are many ways to specify completion on the command line. We'll talk about only one main form in this workshop that should get you comfortable with completion. When you are ready for more, see the man page, or come back to this workshop in a few weeks. (When more will be added)

The syntax of the form we'll discuss is essentially:

compctl [ -CDT ] options [command ...]

You can see all current definitions in a short form by typing compctl with no arguments.

Some examples

Let's try an example. You have a certain set of hosts you like to login to often. A lot of the names are long and cumbersome to type. You'd like to be able to type only a couple of characters and then hit < TAB > to have zsh finish the hostname for you. First, we place a list of hosts that we want to complete in a file, one per line, and call it comp_login_cmds:

  > cat ./zsh/comp_login_cmds
  www.nebcorp.com
  www.acm.uiuc.edu
  schrof.net
  www.meat.net
  www.zsh.org
  > 
  

Now for the command line. Let's throw in some cool tricks, too. We'll start with the full command line, and break it down:

compctl -k "( ` < ./zsh/comp_login_cmds `)" telnet rlogin rsh ssh

Now, we look at the command line above:

There you have it. Now, you can type:

> ssh www.< TAB >

and zsh will present you with all items that start with www. If you had entered:

> ssh www.a< TAB >

zsh would know that there is only one item that starts with www.a, and therefore replace it with www.acm.uiuc.edu


Related Items