ZSH Juju Tab-Completion


#1

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

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!


#3

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.


#4

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


#5

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.


The Juju Show #45 - Jujuna OpenStack upgrades tested