ZSH Juju Tab-Completion

In my ongoing quest to make life difficult for myself, I was working with Juju in a zsh termnial environment. Juju’s tab completion is great, and I rely on it heavily. It seems to not work out of the box on zsh.

Here’s how I got it working: (in an Ubuntu Bionic env, and also in a Win10/WSL/Bionic env)

At the end of ~/.zshrc add these lines:

autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
source /usr/share/bash-completion/completions/juju

And restart your shell. I hope it works for you!

2 Likes

Oooh, as a zsh user I can’t wait to try this. I guess I’ve never gotten hooked on tab completion because I’ve never really had it in my shell. Now I get to see what I’ve been missing!

Now I remember trying this among many other things.

I keep getting:

_JUJU_2_complete_with_func:24: command not found: _get_comp_words_by_ref   
_JUJU_2_complete_with_func:26: command not found: __ltrim_colon_completions

Though even when reverting to bash I couldn’t get it to work.

I have an esoteric set-up, built on Ubuntu Server with Xmonad.

It does that for me too, but the completion works. Like this:
https://i.imgur.com/PUM2t7N.gifv

The reason why autocomplete breaks with zsh is that those functions are not implemented by bashcompinit/compinit.

I yanked the missing bits from github.com/git/git-completion.bash and github.com/scop/bash-completion and opened a juju PR to get zsh-autocompletion working.

2 Likes

Fwiw, ohmyzsh already takes care of the autoload bits.

And if you use the juju plugin for ohmyzsh then auto-completions are applied for you.