From daaa103cec9fc6f80ddad385922ae26ff2794df2 Mon Sep 17 00:00:00 2001 From: Rasmus Skovgaard Lauritsen Date: Sat, 5 Sep 2026 20:19:45 +0200 Subject: [PATCH] feat(gcx): add completion plugin for Grafana's gcx (#13950) * feat(gcx): add completion plugin * fix(gcx): write completion cache atomically --- plugins/gcx/README.md | 18 ++++++++++++++++++ plugins/gcx/gcx.plugin.zsh | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 plugins/gcx/README.md create mode 100644 plugins/gcx/gcx.plugin.zsh diff --git a/plugins/gcx/README.md b/plugins/gcx/README.md new file mode 100644 index 000000000..3dc02bb37 --- /dev/null +++ b/plugins/gcx/README.md @@ -0,0 +1,18 @@ +# Grafana CLI plugin + +This plugin adds completion for the [Grafana CLI (gcx)](https://github.com/grafana/gcx). + +To use it, add `gcx` to the plugins array in your zshrc file: + +```zsh +plugins=(... gcx) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and automatically updates it when the +plugin is loaded, which is usually when you start a new terminal emulator. + +The cache is stored at `$ZSH_CACHE_DIR/completions/_gcx`. diff --git a/plugins/gcx/gcx.plugin.zsh b/plugins/gcx/gcx.plugin.zsh new file mode 100644 index 000000000..278c16692 --- /dev/null +++ b/plugins/gcx/gcx.plugin.zsh @@ -0,0 +1,18 @@ +# Autocompletion for the Grafana CLI (gcx). +if (( ! $+commands[gcx] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `gcx`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_gcx" ]]; then + typeset -g -A _comps + autoload -Uz _gcx + _comps[gcx]=_gcx +fi + +zmodload -F zsh/files b:zf_mv +() { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/_gcx" + zf_mv -f -- =( gcx completion zsh ) "$TMPPREFIX" +} &|