Skip to content

Commit

Permalink
refactor(gem): favor built-in zsh completion for gem (ohmyzsh#12576)
Browse files Browse the repository at this point in the history
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: zsh-users/zsh@9881778
  • Loading branch information
mcornella committed Jul 23, 2024
1 parent 25836e2 commit a2bf5c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
File renamed without changes.
27 changes: 26 additions & 1 deletion plugins/gem/gem.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

# 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"
} &|

0 comments on commit a2bf5c7

Please sign in to comment.