diff --git a/plugins/cdk/README.md b/plugins/cdk/README.md new file mode 100644 index 000000000..b5c87ee93 --- /dev/null +++ b/plugins/cdk/README.md @@ -0,0 +1,15 @@ +# AWS CDK plugin + +This plugin adds completion for the [AWS Cloud Development Kit (CDK)](https://aws.amazon.com/cdk/) CLI. + +To use it, add `cdk` to the plugins array in your zshrc file: + +```zsh +plugins=(... cdk) +``` + +If the `cdk` command is installed globally, the plugin uses it directly. If `cdk` is not found but `npx` is +available, the plugin defines a `cdk` wrapper that runs `npx -- cdk`, which supports project-local CDK +installations. + +This plugin does not add any aliases. diff --git a/plugins/cdk/cdk.plugin.zsh b/plugins/cdk/cdk.plugin.zsh new file mode 100644 index 000000000..67f8170e2 --- /dev/null +++ b/plugins/cdk/cdk.plugin.zsh @@ -0,0 +1,22 @@ +# AWS CDK plugin +# +# Adds completion for the AWS CDK CLI. If `cdk` is not installed globally but +# `npx` is available, define a wrapper so project-local CDK installations work. + +if (( ! $+commands[cdk] )); then + if (( ! $+commands[npx] )); then + return + fi + + function cdk() { + npx -- cdk "$@" + } +fi + +function _cdk_yargs_completions() { + local -a reply + reply=(${(f)"$(COMP_CWORD="$((CURRENT - 1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" cdk --get-yargs-completions "${words[@]}")"}) + _describe 'values' reply +} + +compdef _cdk_yargs_completions cdk