aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

feat: Shell completion #6842

Open JamesKyburz opened 8 months ago

JamesKyburz commented 8 months ago

Support shell completion?

click has support for completion documented here

Is there any reason we shouldn't support it?

Proposal

Was thinking something along the lines of adding the allowing the following in ~/.zshrc, or ~/.bashrc

source <(sam completion)

Where we would detect if the completion is for zsh or bash, and error if the shell is unsupported.

sidhujus commented 8 months ago

Hi @JamesKyburz thanks for the feature request! I'll bring this up with the team.

super132 commented 6 months ago

As an alternative, you could try using Code Whisperer CLI and it gives smart auto-completion for SAM CLI commands.

neilramsay commented 5 months ago

As an optimisation to prevent shells having to generate completions each startup, I recommend a change to the proposal for bash:

#! /bin/bash
sam completion > ${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/sam

This is based off the bash-completion documentation:

Q. Where should I install my own local completions?

A. Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/.local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded automatically on demand when the respective command is being completed. See also the next question's answer for considerations for these files' names, they apply here as well. Alternatively, you can write them directly in ~/.bash_completion which is loaded eagerly by our main script.

Someone more familiar with zsh will need to provide guidance their completion system.