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.
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: