6

I installed awscli from brew.

The amazon instructions refer to a shell script, aws_zsh_completer.sh that doesn't appear to be included. I do have an /usr/local/bin/aws_completer.

How do I make the autocompleter for aws work on zsh in iTerm2 on macos Catalina?

bmike
  • 235,889
John2095
  • 804
  • Ugh - I got it working but can't get my .zshrc quite right yet. My answer is incomplete so far – bmike Dec 18 '19 at 03:24

2 Answers2

12

I know this question is kinda old but there's a better answer if you're running awscli 2.1 or greater and are using oh-my-zsh. Basically, to confirm this solution run this command from your zsh shell

complete -C aws_completer aws

Then you can test to make sure the completion works by typing partial aws command like aws s3 and pressing tab.

If this works then you can add the complete -C aws_completer aws to you .zshrc startup profile. I got this from the following article:

Astro269
  • 121
  • 2
    I'm not running OMZ, but when I run complete... in the shell, autocomplete starts working. But when I put the identical command in my .zshrc and start a new shell, no autocomplete. Confusing. – Mike B Mar 16 '21 at 00:54
4

OK - completions need a bit of help to get going - brew includes the definitions, but you have to prime the completions mechanism if you haven't enabled one yet.

brew install zsh-completions
autoload -Uz compinit
compinit

Press y when asked to ignore insecure directories

Then to test things out run the initialization:

autoload bashcompinit && bashcompinit
source /usr/local/bin/aws_zsh_completer.sh

I know - it says bash and you use zsh - you can type aws followed by a space and gla and tab and it should pause a bit and complete to the glacier command instead of file completion:

aws gla

Once that's set, you have to set up your .zshrc and likely fix the insecure compinit error by removing write permissions on some directories.

bmike
  • 235,889
  • It works in the current shell after the first stanza (down to compinit) but there is no /usr/local/bin/aws_zsh_completer.sh file. Not sure how to make it stick.. put autoload && compinit in the zshrc? Meanwhile compinit wants me to remove write to /usr/local/share from the admin group?! – John2095 Dec 18 '19 at 04:03
  • @John2095 yeah. It’s a mess. The insecure compinit link fixed the share perms for me. – bmike Dec 18 '19 at 04:35