Not sure where to put completions with Oh My Zsh
Asked Answered
R

3

8

I'm using zsh and oh my zsh, and I'm a bit confused about where to put completion files.

For example, when installing kind, I'm doing this:

brew install kind
kind complete zsh > ~/.oh-my-zsh/cache/completions/_kind

And I expect that completions for kind would start working. Am I putting them in the wrong dir?

If I do autoload -U compinit && compinit in the current terminal, completions work until I restart the terminal.

My .zshrc is pretty standard I think, this is basically what I've got:

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

export ZSH="$HOME/.oh-my-zsh"

DISABLE_MAGIC_FUNCTIONS="true"

plugins=(
  git
  gh
  docker
  docker-compose
  kubectl
  helm
  dotnet
  node
  npm
  github
  zsh-syntax-highlighting
  zsh-autosuggestions
  history-substring-search
  terraform)
autoload -U compinit && compinit

source $ZSH/oh-my-zsh.sh

Does the autoload -U compinit && compinit has to happen after I source oh my zsh? If so, why? 🤔

Report answered 13/3, 2022 at 12:19 Comment(1)
Linking this for other users github.com/ohmyzsh/ohmyzsh/discussions/…Semifinal
A
2

The solution above is working, thank you @Nishant Mittal, but I doubt it will remain after an omz update. I found a more stable solution, thanks kubectl plugin.

cat ${HOME}/.oh-my-zsh/custom/plugins/dind/dind.plugin.zsh
dind completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_dind" &| 

Then add it in plugins section of your ~/.zshrc . I presume it will update the completion automatically when dind binary is upgraded.

Ayer answered 2/3, 2023 at 8:37 Comment(0)
P
1

Have you tried putting the completions not in the cache directory.

kind complete zsh > ~/.oh-my-zsh/completions/_kind
Pendulous answered 28/7, 2022 at 7:5 Comment(0)
Y
0

echo 'source <(kind completion zsh )' >>~/.zshrc

Yuhas answered 13/4 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.