kubie icon indicating copy to clipboard operation
kubie copied to clipboard

zsh: kubectl auto-complete does not work in the kubie sub shell

Open Dentrax opened this issue 3 years ago • 5 comments

☸ kind-kind (default) in ~ took 2m47s
$ k get <TAB>  # works
$ kubie ctx foo  # new shell
$ k get <TAB>  # does not work
$ zsh --version
zsh 5.8 (x86_64-apple-darwin20.1.0)

Any ideas?

Dentrax avatar Jul 26 '21 13:07 Dentrax

Yeah, could be an issue with the custom init script we use https://github.com/sbstp/kubie/blob/master/src/shell/zsh.rs

sbstp avatar Jul 26 '21 14:07 sbstp

I'm also having this issue in bash.

w3irdrobot avatar Aug 27 '21 13:08 w3irdrobot

Me too. It works kind of strange. Part of auto completion works, part not. For example get pods,secrets,daemonset works. And get deploy, statefullset doesn't. Weird. Sometimes exit the shell completely helps, but then it return without reason.

andrey-gava avatar Sep 07 '21 05:09 andrey-gava

So I think kubie is mangling ZDOTDIR environment variable, which some ZSH plugins depend on to initialize correctly. For example, prezto is using this initialization code inside .zshrc

if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
  source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi

Kubie should probably either restore or unset ZDOTDIR before loading users' .zshrc:

# Backup Kubie's ZDOTDIR
kubie_ZDOTDIR=$ZDOTDIR

# Restore or unset users' ZDOTDIR
if (( ${+_KUBIE_USER_ZDOTDIR} )); then
    export ZDOTDIR=$_KUBIE_USER_ZDOTDIR
else
    unset ZDOTDIR
fi

# Load users' .zshrc with their ZDOTDIR
if [[ -f "${ZDOTDIR:-$HOME}/.zshrc" ]] ; then
    source "${ZDOTDIR:-$HOME}/.zshrc"
fi

# Restore Kubie's ZDOTDIR
ZDOTDIR=$kubie_ZDOTDIR

kien-truong avatar Feb 23 '22 09:02 kien-truong

Though perhaps a better way is to unset / restore the user's ZDOTDIR immediately at the start of the script.

kien-truong avatar Feb 23 '22 10:02 kien-truong