From 92c28758b93b822a5943287f1dd756ccb6cb8037 Mon Sep 17 00:00:00 2001 From: Jonathan Stacks Date: Wed, 27 Nov 2024 01:13:04 -0600 Subject: [PATCH] feat(talosctl): Add completions for talosctl Signed-off-by: Jonathan Stacks --- plugins/talosctl/README.md | 20 ++++++++++++++++++++ plugins/talosctl/talosctl.plugin.zsh | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/talosctl/README.md create mode 100644 plugins/talosctl/talosctl.plugin.zsh diff --git a/plugins/talosctl/README.md b/plugins/talosctl/README.md new file mode 100644 index 000000000..750104e10 --- /dev/null +++ b/plugins/talosctl/README.md @@ -0,0 +1,20 @@ +# talosctl plugin + +This plugin adds completion for the [talosctl](https://docs.siderolabs.com/talos/v1.12/learn-more/talosctl) CLI for managing [Talos](https://github.com/siderolabs/talos) Linux. + +To use it, add `talosctl` to the plugins array in your zshrc file: + +```zsh +plugins=(... talosctl) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated asynchronously when the plugin is +loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE/completions/_talosctl` completions script diff --git a/plugins/talosctl/talosctl.plugin.zsh b/plugins/talosctl/talosctl.plugin.zsh new file mode 100644 index 000000000..25c6d45d6 --- /dev/null +++ b/plugins/talosctl/talosctl.plugin.zsh @@ -0,0 +1,14 @@ +# Autocompletion for talosctl +if (( ! $+commands[talosctl] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `talosctl`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_talosctl" ]]; then + typeset -g -A _comps + autoload -Uz _talosctl + _comps[talosctl]=_talosctl +fi + +talosctl completion zsh >| "$ZSH_CACHE_DIR/completions/_talosctl" &|