How to fix autocompletion for LXD's lxc commands on Arch?

Because all LXD commands start with lxc (for example lxc config edit), Arch tries to use LXCs auto complete for the commands and so auto complete doesn’t work at all for LXD commands.

I’ve successfully fixed this by porting over the auto complete from a snap install (taking the lxd.lxc file and the lxc symbolic link and putting them in /usr/share/bash-completions/completions) but every time either LXC or the auto completion package updates, the symbolic link file gets overwritten by the new LXC auto-completions and everything breaks again. Is there any way I can override this auto completion permanently? I suspect I can use my .bashrc or bash_profile file, but I’m unsure exactly how.

Hi, you solve the issue?, I’m facing the same problem

No, I ended up moving to ZSH instead of bash and using the ZSH LXD autocomplete plugin. that works very well for me so far.

1 Like

that works for me too, thanks

You may want to contact your distro package maintainers and propose them to fix this. Since lxc doesn’t install “lxc” binary, you’re right the bashcomp aliases shouldn’t link to that either. I personally believe lxd will be more important / popular going to the future, so you should let lxd take precedence over lxc with that. Of course anyone is able to do these configurations locally too.

Here’s how it’s handled in Gentoo:
gentoo/lxc-4.0.12.ebuild at master · gentoo/gentoo · GitHub (lines 140-149)
gentoo/lxd-4.0.9-r3.ebuild at master · gentoo/gentoo · GitHub

I solve the issue in manjaro adding these lines on the .zshrc file

autoload bashcompinit
bashcompinit
export -f _have() { which $@ >/dev/null }
source /var/lib/snapd/snap/lxd/current/etc/bash_completion.d/snap.lxd.lxc