Add completion

main v0.0.4
William Beuil 2021-01-25 23:39:27 +01:00
parent d19211ed64
commit aa541929c3
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
4 changed files with 94 additions and 0 deletions

View File

@ -155,3 +155,52 @@ Then, you just need to remove its root directory:
```console ```console
$ rm -rf `dctlenv root` $ rm -rf `dctlenv root`
``` ```
## Completion scripts
Completion scripts are available to use inside the `completions` folder.
### Bash
```console
# Linux:
$ cp completions/dctlenv.bash > /etc/bash_completion.d/dctlenv
# MacOS:
$ cp completions/dctlenv.bash > /usr/local/etc/bash_completion.d/dctlenv
```
Remember to open a new shell to test the functionality.
### Zsh
If shell completion is not already enabled in your environment, you will need to enable it. You can execute the following once:
```console
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
```
Then, place the completion script in your completion folder listed in your `fpath` if it already exists. Otherwise, you can create a directory, add it to your `fpath` and copy the file in it:
```console
$ cp completions/dctlenv.zsh > fpath/completion_folder/_dctlenv
```
#### Oh-My-Zsh
```console
$ mkdir -p ~/.oh-my-zsh/completions
$ cp completions/dctlenv.zsh > ~/.oh-my-zsh/completions/_dctlenv
```
You will need to start a new shell for this setup to take effect.
### Fish
```console
$ cp completions/dctlenv.fish > ~/.config/fish/completions/dctlenv.fish
```
Remember to create the directory if it's not already there `mkdir -p ~/.config/fish/completions/`.
Remember to open a new shell to test the functionality.

11
completions/dctlenv.bash Normal file
View File

@ -0,0 +1,11 @@
# bash completion for dctlenv
_dctlenv() {
if [ "${#COMP_WORDS[@]}" != "2" ]; then
return
fi
COMPREPLY=($(compgen -W "help install list list-remote uninstall use version" -- "${COMP_WORDS[1]}"))
}
complete -F _dctlenv dctlenv

11
completions/dctlenv.fish Normal file
View File

@ -0,0 +1,11 @@
# fish completion for dctlenv
set -l commands help install list list-remote uninstall use version
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a help -d 'Show the help output'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a install -d 'Install a specific version of driftctl'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a list -d 'List all installed versions'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a list-remote -d 'List all installable versions'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a uninstall -d 'Uninstall a specific version of driftctl'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a use -d 'Switch a version to use'
complete -f -c dctlenv -n "not __fish_seen_subcommand_from $commands" -a version -d 'Display dctlenv version'

23
completions/dctlenv.zsh Normal file
View File

@ -0,0 +1,23 @@
#compdef _dctlenv dctlenv
_dctlenv() {
local -a commands
_arguments -C \
"1: :->cmnds"
case $state in
cmnds)
commands=(
"install:Install a specific version of driftctl"
"uninstall:Uninstall a specific version of driftctl"
"use:Switch a version to use"
"list:List all installed versions"
"list-remote:List all installable versions"
"version:Display dctlenv version"
"help:Show the help output"
)
_describe "command" commands
;;
esac
}