Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI command completion with fish shell

Has anybody been able to set up auto-complete for the AWS CLI with fish shell? The AWS documentation only offers the guide for bash, tcsh, and zsh.

Bash exports the variables COMP_LINE and COMP_POINT that is used by the aws_completer script provided by the Amazon. Is there any equivalent for fish? I'm new with the fish shell and I'm giving it a try.

like image 281
Osi Avatar asked Aug 31 '25 03:08

Osi


1 Answers

Building upon David Roussel's answers I cooked up the following:

function __fish_complete_aws
    env COMP_LINE=(commandline -pc) aws_completer | tr -d ' '
end

complete -c aws -f -a "(__fish_complete_aws)"

Put this in a file $HOME/.config/fish/completions/aws.fish so fish can autoload it when necessary.

aws_completer appends a space after every option it prints and that gets escaped as \ so trimming it solves the trailing backslashes.

Now we can test the completion with the following:

> complete -C'aws co'
codebuild
codecommit
codepipeline
codestar
cognito-identity
cognito-idp
cognito-sync
comprehend
comprehendmedical
connect
configure
configservice

Using the commandline -c helps if you move back the cursor since it cuts the command line at the cursor so aws_completer can offer the right completions.

like image 172
tmichel Avatar answered Sep 02 '25 17:09

tmichel