diff --git a/cmd/root.go b/cmd/root.go index 630775b24..decd1cadf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -42,6 +42,7 @@ var rootCmd = &cobra.Command{ Use: "containerlab", Short: "deploy container based lab environments with a user-defined interconnections", PersistentPreRunE: preRunFn, + Aliases: []string{"clab"}, } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/docs/cmd/completion.md b/docs/cmd/completion.md index 33626c6a5..32553d277 100644 --- a/docs/cmd/completion.md +++ b/docs/cmd/completion.md @@ -1,52 +1,83 @@ # shell completions -### Description +## Description The `completion` command generates shell completions for bash/zsh/fish shells. -### Usage +## Usage `containerlab completion [arg]` -#### Bash completions +### Bash completions + +> Ensure that bash-completion is installed on your system. + +To load completions for the current session: ```bash source <(containerlab completion bash) ``` -To load completions for each session, execute once: +To load completions for each session: + +/// tab | Linux + ```bash -# linux -$ containerlab completion bash > /etc/bash_completion.d/containerlab +containerlab completion bash > /etc/bash_completion.d/containerlab +``` -# macOS -$ containerlab completion bash > /usr/local/etc/bash_completion.d/containerlab +/// +/// tab | macOS + +```bash +containerlab completion bash > /usr/local/etc/bash_completion.d/containerlab ``` -#### ZSH completions -If shell completion is not already enabled in your environment, users will need to enable it. To do so, execute the following once: +/// + +To also autocomplete for `clab` command alias, add the following to your `.bashrc` or `.bash_profile`: + ```bash -echo "autoload -U compinit; compinit" >> ~/.zshrc +complete -o default -F __start_containerlab clab ``` -To load completions for each session, execute once: +### 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: + +```bash +autoload -U compinit; compinit +``` + +To load completions for each session generate the completion script and store it somewhere in your `$fpath`: + +```bash +clab completion zsh | \ +sed '1,2c\#compdef containerlab clab\ncompdef _containerlab containerlab clab' > \ +~/.oh-my-zsh/custom/completions/_containerlab +``` + +/// admonition | Completion script location + type: subtle-note +`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 to the list by adding this in your .zshrc file: + ```bash -containerlab completion zsh > "${fpath[1]}/_containerlab" +fpath=(~/.oh-my-zsh/custom/completions $fpath) ``` -!!!info - Note: `$fpath[1]` in this command refers to the first path in `$fpath`. Ensure you - use the index pointing to the completion folder, find the correct index by inspecting - the output of `echo $fpath` +And then using `~/.oh-my-zsh/custom/completions` for your completions. +/// Start a new shell for this setup to take effect. -#### Fish completions +### Fish completions + ```bash containerlab completion fish | source ``` To load completions for each session, execute once: + ``` containerlab completion fish > ~/.config/fish/completions/containerlab.fish -``` \ No newline at end of file +```