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
Diff
1diff --git a/plugins/gem/_gem b/plugins/gem/completions/_gem
2rename from plugins/gem/_gem
3rename to plugins/gem/completions/_gem
4diff --git a/plugins/gem/gem.plugin.zsh b/plugins/gem/gem.plugin.zsh
5index 938f5c993fe084fe77aa36410c6147583ca9c7e4..b8a49fb566b6dea58404e857e67f957e47930f04 100644
6--- a/plugins/gem/gem.plugin.zsh
7+++ b/plugins/gem/gem.plugin.zsh
8@@ -4,4 +4,29 @@ alias gemp="gem push *.gem"
9 # gemy GEM 0.0.0 = gem yank GEM -v 0.0.0
10 function gemy {
11 gem yank $1 -v $2
12-}
13+}
14+
15+# If the completion file doesn't exist yet, we need to autoload it and
16+# bind it to `gem`. Otherwise, compinit will have already done that.
17+if [[ ! -f "$ZSH_CACHE_DIR/completions/_gem" ]]; then
18+ typeset -g -A _comps
19+ autoload -Uz _gem
20+ _comps[docker]=_gem
21+fi
22+
23+# zsh 5.5 already provides completion for `_gem`. With this we ensure that
24+# our provided completion (which is not optimal but is enough in most cases)
25+# is used for older versions
26+autoload -Uz is-at-least
27+if is-at-least 5.5; then
28+ return 0
29+fi
30+
31+{
32+ # Standarized $0 handling
33+ # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
34+ 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
35+ 0="${${(M)0:#/*}:-$PWD/$0}"
36+
37+ command cp -f "${0:h}/completions/_gem" "$ZSH_CACHE_DIR/completions/_gem"
38+} &|