From 4bdcaad01aab9532c59ea1a3c0fd1f5ad3daaa52 Mon Sep 17 00:00:00 2001 From: Gore Williams <88089185+gorewilliams@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:14:48 +0300 Subject: [PATCH] feat(ruff): add plugin for Asral's ruff (#13604) --- plugins/ruff/README.md | 22 ++++++++++++++++++++++ plugins/ruff/ruff.plugin.zsh | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 plugins/ruff/README.md create mode 100644 plugins/ruff/ruff.plugin.zsh diff --git a/plugins/ruff/README.md b/plugins/ruff/README.md new file mode 100644 index 000000000..ab69d7fe8 --- /dev/null +++ b/plugins/ruff/README.md @@ -0,0 +1,22 @@ +# ruff plugin + +This plugin automatically installs [ruff](https://github.com/astral-sh/ruff)'s completions for you, +and keeps them up to date. It also adds convenient aliases for common usage. + +To use it, add `ruff` to the plugins array in your zshrc file: + +```zsh +plugins=(... ruff) +``` + +## Aliases + +| Alias | Command | Description | +| :---- | -------------------- | :----------------------------------------------------------- | +| ruc | `ruff check` | Run Ruff linter on the given files or directories | +| rucf | `ruff check --fix` | Run Ruff linter and fix auto-fixable issues | +| ruf | `ruff format` | Run the Ruff formatter on the given files or directories | +| rufc | `ruff format --check`| Check if files are already formatted without making changes | +| rur | `ruff rule` | Explain a rule (or all rules) | +| rul | `ruff linter` | List all supported upstream linters | +| rucl | `ruff clean` | Clear any caches in the current directory and subdirectories | diff --git a/plugins/ruff/ruff.plugin.zsh b/plugins/ruff/ruff.plugin.zsh new file mode 100644 index 000000000..dca264a54 --- /dev/null +++ b/plugins/ruff/ruff.plugin.zsh @@ -0,0 +1,27 @@ +# Return immediately if ruff is not found +if (( ! ${+commands[ruff]} )); then + return +fi + +alias ruc='ruff check' +alias rucf='ruff check --fix' +alias ruf='ruff format' +alias rufc='ruff format --check' +alias rur='ruff rule' +alias rul='ruff linter' +alias rucl='ruff clean' + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_ruff" ]]; then + typeset -g -A _comps + autoload -Uz _ruff + _comps[ruff]=_ruff +fi + +# Overwrites the file each time as completions might change with ruff versions. +zmodload -F zsh/files b:zf_mv +() { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/_ruff" + zf_mv -f -- =( ruff generate-shell-completion zsh ) "$TMPPREFIX" +} &|