From aa541929c3359abfee5be0c627a5ae4ab087de2c Mon Sep 17 00:00:00 2001 From: William Beuil Date: Mon, 25 Jan 2021 23:39:27 +0100 Subject: [PATCH] Add completion --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++ completions/dctlenv.bash | 11 +++++++++ completions/dctlenv.fish | 11 +++++++++ completions/dctlenv.zsh | 23 +++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 completions/dctlenv.bash create mode 100644 completions/dctlenv.fish create mode 100644 completions/dctlenv.zsh diff --git a/README.md b/README.md index abb4297..8fce223 100644 --- a/README.md +++ b/README.md @@ -155,3 +155,52 @@ Then, you just need to remove its root directory: ```console $ 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. diff --git a/completions/dctlenv.bash b/completions/dctlenv.bash new file mode 100644 index 0000000..5d2059b --- /dev/null +++ b/completions/dctlenv.bash @@ -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 diff --git a/completions/dctlenv.fish b/completions/dctlenv.fish new file mode 100644 index 0000000..c88f981 --- /dev/null +++ b/completions/dctlenv.fish @@ -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' diff --git a/completions/dctlenv.zsh b/completions/dctlenv.zsh new file mode 100644 index 0000000..f8790e4 --- /dev/null +++ b/completions/dctlenv.zsh @@ -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 +}