-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt completions for clab alias (#2388)
- Loading branch information
Showing
2 changed files
with
51 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` | ||
``` |