perlpunk / shell-completions

Collection of shell (bash, zsh) tab completion scripts for various command line tools
MIT License
36 stars 7 forks source link
autocomplete bash completion tab-completion yaml zsh

Collection of shell tab completion scripts for various command line tools

These scripts are automatically generated from YAML files which can be found under specs/.

The format supports nested subcommands, specifying enums for possible parameters/option values and dynamic completion calling an external command.

The generation is done with the appspec tool (see "Developing" below).

Currently it supports bash and zsh completions.

List of commands

Installation

git clone https://github.com/perlpunk/shell-completions

Usage

Look into the specs/commandname.yaml for specific usage instructions.

Bash

For a specific script, just source it:

$ source /path/to/shell-completions/bash/commandname.bash

Put this in your .bashrc for using all completions:

for i in /path/to/shell-completions/bash/*.bash; do source $i; done

Using only one <TAB> keypress like in zsh

You can enable this by putting the following in your ~/.inputrc:

set show-all-if-ambiguous on

See GNU Readline Init File Syntax.

Zsh

For activating the completions, you can do:

% fpath=(/path/to/shell-completions/zsh $fpath)
% compinit

To just try out completion for one specific script, you can also do:

% source /path/to/shell-completions/zsh/_commandname
% compdef _commandname commandname

Put this in your .zshrc for activating all completions:

# before the compinit call
fpath=('/path/to/shell-completions/zsh' $fpath)

This way zsh won't load all functions at startup, but the completions will get autoloaded dynamically when the command is first used.

When developing a new completion, after a change it's enough to source it, without calling compinit again:

% source /path/to/shell-completions/zsh/_commandname

Developing

The appspec tool is used to generate the completions. You don't need it if you just want to use the completions.

If you want to modify or add a new completion, install the App::AppSpec perl module, or use the standalone script:

% git clone https://github.com/perlpunk/App-AppSpec-p5 -b standalone appspec
% PATH=$PWD/appspec/bin:$PATH

For more details see https://github.com/perlpunk/App-AppSpec-p5.

Create a new specification specs/commandname.yaml and type:

make commandname

See Also