Skip to content

shell completions#

Description#

The completion command generates shell completions for bash/zsh/fish shells.

All command line arguments can be also provided via environment variables (CLI flags take precedence). The environment variable names are constructed by prepending CLAB_ to the flag name, then adding the command path and ending with the flag name in its full form, all in uppercase and with hyphens replaced by underscores.

For example, the --max-workers flag for the deploy command can be set via CLAB_DEPLOY_MAX_WORKERS environment variable.
Or CLAB_INSPECT_ALL=1 to set --all flag for the inspect command.
Or CLAB_TOPO=srlinux.dev/clab-srl clab dep -c to deploy a lab with the topology passed via environment variable.

Usage#

containerlab completion [arg]

Bash completions#

Ensure that bash-completion is installed on your system.

To load completions for the current session:

source <(containerlab completion bash)

To load completions for each session:

containerlab completion bash > /etc/bash_completion.d/containerlab
containerlab completion bash > /usr/local/etc/bash_completion.d/containerlab

To also autocomplete for clab command alias, add the following to your .bashrc or .bash_profile:

complete -o default -F __start_containerlab clab

ZSH completions#

If shell completion is not already enabled in your environment you have to enable it by ensuring zsh completions are loaded. The following can be added to your zshrc:

autoload -U compinit; compinit

To load completions for each session generate the completion script and store it somewhere in your $fpath:

clab completion zsh | \
sed '1,2c\#compdef containerlab clab\ncompdef _containerlab containerlab clab' > \
~/.oh-my-zsh/custom/completions/_containerlab

Completion script location

The example above uses the ~/.oh-my-zsh/custom/completions directory, which might not exist by default.

echo $fpath will show the directories zsh reads files from. You can either use one of the available completions directories from this list or add a new directory:

mkdir -p ~/.oh-my-zsh/custom/completions

and then add this directory to the fpath list by adding it in your .zshrc file:

fpath=(~/.oh-my-zsh/custom/completions $fpath)

Now you can use ~/.oh-my-zsh/custom/completions for your completions as shown above.

Start a new shell for this setup to take effect.

Fish completions#

containerlab completion fish | source

To load clab and containerlab completions for each session, execute once:

containerlab completion fish > ~/.config/fish/completions/containerlab.fish
echo "complete --command clab --wraps containerlab" > ~/.config/fish/completions/clab.fish
fish_update_completions