diff options
| author | Marc Cornellà <marc@mcornella.com> | 2024-07-23 15:59:38 +0200 |
|---|---|---|
| committer | Marc Cornellà <marc@mcornella.com> | 2024-07-23 18:56:01 +0200 |
| commit | a2bf5c7b99ef1c10d335ed79236dacbb78dd0639 (patch) | |
| tree | 89e4b7c4ae2441e91f790bc46424039d2869baf8 /plugins | |
| parent | 25836e227c58f98af3136d0721ae8ee78271e1c5 (diff) | |
| download | zsh-a2bf5c7b99ef1c10d335ed79236dacbb78dd0639.tar.gz zsh-a2bf5c7b99ef1c10d335ed79236dacbb78dd0639.tar.bz2 zsh-a2bf5c7b99ef1c10d335ed79236dacbb78dd0639.zip | |
refactor(gem): favor built-in zsh completion for `gem` (#12576)
Completion for `gem` was included in zsh 5.5 and newer. This change
only uses the Oh My Zsh one if running an older version.
Reference: https://github.com/zsh-users/zsh/commit/9881778d48caf842f794d986bc9befebf0fb01c2
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/gem/completions/_gem (renamed from plugins/gem/_gem) | 0 | ||||
| -rw-r--r-- | plugins/gem/gem.plugin.zsh | 27 |
2 files changed, 26 insertions, 1 deletions
diff --git a/plugins/gem/_gem b/plugins/gem/completions/_gem index 92feebe95..92feebe95 100644 --- a/plugins/gem/_gem +++ b/plugins/gem/completions/_gem diff --git a/plugins/gem/gem.plugin.zsh b/plugins/gem/gem.plugin.zsh index 938f5c993..b8a49fb56 100644 --- a/plugins/gem/gem.plugin.zsh +++ b/plugins/gem/gem.plugin.zsh @@ -4,4 +4,29 @@ alias gemp="gem push *.gem" # gemy GEM 0.0.0 = gem yank GEM -v 0.0.0 function gemy { gem yank $1 -v $2 -}
\ No newline at end of file +} + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `gem`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_gem" ]]; then + typeset -g -A _comps + autoload -Uz _gem + _comps[docker]=_gem +fi + +# zsh 5.5 already provides completion for `_gem`. With this we ensure that +# our provided completion (which is not optimal but is enough in most cases) +# is used for older versions +autoload -Uz is-at-least +if is-at-least 5.5; then + return 0 +fi + +{ + # Standarized $0 handling + # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html + 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" + 0="${${(M)0:#/*}:-$PWD/$0}" + + command cp -f "${0:h}/completions/_gem" "$ZSH_CACHE_DIR/completions/_gem" +} &| |
