http://www.zsh.org) fabulous tab completion system. By adding the following two lines to your $HOME/.zshrc file, you can use the tab key to not only expand file names, but also get lists of command-line options.

" />
x
Loading
 Loading
Hello, Guest | Login | Register

Writing Zsh Completion Functions

If you’ve been reading this column for the past few months, you’ve learned about the zsh shell’s (http://www.zsh.org) fabulous tab completion system. By adding the following two lines to your $HOME/.zshrc file, you can use the tab key to not only expand file names, but also get lists of command-line options.

If you’ve been reading this column for the past few months, you’ve learned about the zsh shell’s (http://www.zsh.org) fabulous tab completion system. By adding the following two lines to your $HOME/.zshrc file, you can use the tab key to not only expand file names, but also get lists of command-line options.

 autoload -U compinit compinit 

To provide the list of command-line options for a given Linux command, zsh executes the completion function associated with that command (i.e., if you type ls and press the tab key, zsh executes the ls completion function). Each completion function lists command options and shows what options require arguments. A completion function is also context-sensitive. For example, type man 1 and hit the tab key. Notice the names of the man pages. Next, type man 3 followed by tab. The list is different. The completion function for man is section-specific.

zsh includes completion functions for many Linux commands, but not all of them. Hang on. Don’t fret. You can extend the capabilities of zsh by writing your own completion functions.

A Caveat

Although it’s actually quite easy to write completion func-tions, you’d never know it by reading the zsh documentation. Currently, there’s no single source of information to quickly teach you how to write them.

The man pages zshcompsys and zshcompwid are the most complete source of information, but they don’t explain how to write a completion function from start to finish. Thus, they are…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace