From f9d07dc1a7ae300976d40655e7232d3241966db0 Mon Sep 17 00:00:00 2001 From: codeDude Date: Thu, 30 Jul 2026 15:59:12 -0600 Subject: [PATCH] Add a autocompletation plugin for forgejo-cli Fix #13909 --- plugins/fj/README.md | 23 +++++++++++++++++++++++ plugins/fj/fj.plugin.zsh | 14 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 plugins/fj/README.md create mode 100644 plugins/fj/fj.plugin.zsh diff --git a/plugins/fj/README.md b/plugins/fj/README.md new file mode 100644 index 000000000..34b0ccbad --- /dev/null +++ b/plugins/fj/README.md @@ -0,0 +1,23 @@ +# Forgejo CLI plugin + +This plugin adds completion for the [Forgejo CLI](https://codeberg.org/forgejo-contrib/forgejo-cli). + +To use it, add `fj` to the plugins array in your zshrc file: + +```zsh +plugins=(... fj) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated when the +plugin is loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH/plugins/fj/_fj` completions script + +- `$ZSH_CACHE_DIR/fj_version` version of Forgejo CLI, used to invalidate + the cache. diff --git a/plugins/fj/fj.plugin.zsh b/plugins/fj/fj.plugin.zsh new file mode 100644 index 000000000..9c937b0c7 --- /dev/null +++ b/plugins/fj/fj.plugin.zsh @@ -0,0 +1,14 @@ +# Autocompletion for the Forgejo CLI (fj). +if (( ! $+commands[fj] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `fj`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_fj" ]]; then + typeset -g -A _comps + autoload -Uz _fj + _comps[fj]=_fj +fi + +fj completion --shell zsh >| "$ZSH_CACHE_DIR/completions/_fj" &|