How do I get the aws cli completion to work with zsh on ubuntu?

I installed aws console cli following the instructions here:

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#install-bundle-other-os

I want to get completion working with zsh. The instructions say to source bin/aws_zsh_completer.sh, which I don't see in the downloaded uncompressed zip installer.

I went ahead and cloned the git repo locally.

Still, sourcing the file doesn't work out of the box. When I attempt to autocomplete, I get python errors complaining about missing modules etc. (e.g., ImportError: No module named awscli.completer)

What am I missing here?


Solution 1:

I think there might be a misprint in the docs.

The CLI section has the following:

zshsource bin/aws_zsh_completer.sh.

% source /usr/local/bin/aws_zsh_completer.sh

The file aws_zsh_completer.sh doesn't live in /usr/local/bin, but I found it in /usr/local/aws/bin I tried this instead:

% source /usr/local/aws/bin/aws_zsh_completer.sh

I didn't try tcsh but I was able to reproduce the same condition with the bash instructions.

I am using MacOS at the moment, and I haven't had a chance to check this out on my Linux box.

Solution 2:

It seems that the actual location of the file varies from installation to installation, so it's better to find the exact location of the file in your system:

cd /                                                                                              
find -name "aws_zsh*" 
./usr/local/bin/aws_zsh_completer.sh

Solution 3:

I found out its located here ~/.local/bin/aws_zsh_completer.sh

# add this to your ~/.zshrc 
# aws completion
source  ~/.local/bin/aws_zsh_completer.sh

Reload your terminal. --> Ubuntu 17.10

Solution 4:

On Ubuntu 17.10 with the awscli package installed:

source /usr/share/zsh/vendor-completions/_awscli