Amazon CodeWhisperer now supports autocompletion and code generation for CLIs

Amazon CodeWhisperer now supports autocompletion and code generation for CLIs

Now you can take CodeWhisperer outside your IDE!

Published Dec 1, 2023
Last Modified Dec 4, 2023
CodeWhisperer is the code companion from AWS packed within the AWS Toolkit which provides AI-powered auto-completion and code generation for IDEs such as Visual Studio Code and the many ones from the JetBrains family including PyCharm. It’s also available on JupyterLab, and AWS console experiences like within its own IDE called AWS Cloud 9 as well as the Lambda console and SageMaker Studio.
Now CodeWhisperer has expanded its support to CLIs as well with two features: autocompletion which allows you to get suggestions for cli commands that you’re typing and natural language prompts which allows you to give it a prompt in English and CodeWhisperer will translate it into a CLI command.

The first thing you gotta do is install the CodeWhisperer App in your computer. At this moment in time (Nov 2023) this is only available for macs. Sorry, Windows users :(

The CodeWhisperer Desktop app is just a simple .dmg so install like anything else on mac. Double click or drag and drop, you’re spoiled for choice! 😆

Once you installed it (should only take a fraction of a second) then go to your Applications folder, find the CodeWhisperer App and open it.
You should see the CodeWhisperer.app listed in your Applications folder after installation.
This should open a window where you’ll find several options for customizing your experience such as tailoring autocompletion behavior, choosing to exclude CLIs for which you don’t suggestions for, edit keyboard bindings, changing the theme, so on and so forth.
Of note those is the Help section which will show you any errors with your set up and help you diagnose any issues you may be having with the integration.
The Help & support tab shows any errors in configuration and helps you troubleshoot any issues.
As you may see in my screenshot I had two problems I needed to solve: my shell integration and enabling accessibility of the CodeWhisperer app.
The shell integration was a false alarm as it turned out. The CodeWhisperer app tried to configure itself for the fish shell but failed; something that is not exactly surprising since I don’t have it installed. This is probably something that will patched/updated in the future so hopefully you won’t see the same if you’re reading this further down the line.
The “Enable Accessibility” error is an important one that you need to address though otherwise CodeWhisperer can’t tweak your terminal to display the suggestions. You can expand the dropdown which reveals an “Enable” button which will open your mac settings screen at the right place or you can also manually navigate to System Settings -> Privacy and Security -> Accessibility to arrive at the same place.
Once there, flip accessibility on for the CodeWhisperer app and voila! Problem solved!
This is all you should need to do to get started using CodeWhisperer in your terminal!
If you installed and configured the CodeWhisperer app correctly, then you should see suggestions coming through!
Open a new terminal and type aws then type space and you should see some suggestions poppping up!
CodeWhisperer showing suggestions after typing the aws command on the cli
The cool thing is that autocompletion doesn’t just work for the AWS CLI but for hundreds of other CLIs including really popular ones like npm, git, python, docker, and more!
CodeWhisperer showing suggestions after typing the git command on the cli
You can exclude clis that you don’t want suggestions to show up for in the CodeWhisperer app UI that you can open from the Applications folder on your Mac like we did above.
Natural Language Prompts
Another cool feature that it comes with is the ability to enter a prompt in English and let CodeWhisperer generate a cli command for you.
To do this you need to type the command cw ai.
Entering the command cw ai to make CodeWhisperer ask for an English prompt
I’m gonna type a prompt that hopefully will generate acli command that lists all files under a directory including the hidden ones.
Typing the prompt : “I want to list all files including hidden ones in the folder called dev under Documents”
I press enter and CodeWhisperer shows me the command it generated alongside some options including one to execute the command.
CodeWhisperer generates the cli command and displays a couple of options for you to choose from including “Execute command”, “Edit command”, “Regenerate answer”, “Ask another question” and “Cancel”.
Great! I press enter and choose to Execute the command and I get exactly what I wanted.
Pretty cool, eh? I particularly like that it gives you an option to edit the command which is a good reminder that you should always double check anything that has been auto-generated before executing it.
I really like where this is going since I don’t know about you but I sometimes still need to google some basic commands as there’s only so much one brain can keep with so many different CLIs and commands and options within those CLIs.
I think it’s really cool to see this kind of functionality which was restricted to IDEs or coding environments sipping out to other corner of our developer’s life.
How about you? Do you think code companions everywhere is the future? Curious to hear your thoughts :)