diff --git a/plugins/cdk/README.md b/plugins/cdk/README.md new file mode 100644 index 000000000..f1708b56e --- /dev/null +++ b/plugins/cdk/README.md @@ -0,0 +1,48 @@ +# CDK plugin + +This plugin adds completion support and convenient aliases for the +[AWS Cloud Development Kit (CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) CLI. + +To use it, add `cdk` to the plugins array in your zshrc file: + +```zsh +plugins=(... cdk) +``` + +## Requirements + +- [Node.js](https://nodejs.org/) +- [aws-cdk](https://www.npmjs.com/package/aws-cdk) installed globally: + + ```sh + npm install -g aws-cdk + ``` + +## Completion + +Completions are generated by running `cdk --completion zsh` and cached in +`$ZSH_CACHE_DIR/completions/_cdk`. The cache is refreshed asynchronously +each time a new shell session starts. + +## Aliases + +| Alias | Command | Description | +|------------|-----------------------------------------------|--------------------------------------| +| `cdkl` | `cdk list` | List all stacks in the app | +| `cdkls` | `cdk ls` | Alias for `cdk list` | +| `cdks` | `cdk synth` | Synthesize CloudFormation template | +| `cdkd` | `cdk deploy` | Deploy a stack | +| `cdkda` | `cdk deploy --all` | Deploy all stacks | +| `cdkdiff` | `cdk diff` | Show diff against deployed stack | +| `cdkdes` | `cdk destroy` | Destroy a stack | +| `cdkdesa` | `cdk destroy --all` | Destroy all stacks | +| `cdkw` | `cdk watch` | Watch for changes and auto-deploy | +| `cdkb` | `cdk bootstrap` | Bootstrap CDK into an AWS account | +| `cdkdf` | `cdk deploy --require-approval never` | Deploy skipping approval prompts | +| `cdkdaf` | `cdk deploy --all --require-approval never` | Deploy all, skip approval prompts | +| `cdkho` | `cdk deploy --hotswap` | Hotswap deploy (Lambda/ECS/etc.) | +| `cdkdoc` | `cdk doctor` | Check CDK environment setup | +| `cdkmeta` | `cdk metadata` | Display stack metadata | +| `cdkctx` | `cdk context` | View cached context values | +| `cdkctxr` | `cdk context --reset` | Reset all cached context values | +| `cdkack` | `cdk acknowledge` | Acknowledge a CDK notice | diff --git a/plugins/cdk/cdk.plugin.zsh b/plugins/cdk/cdk.plugin.zsh new file mode 100644 index 000000000..80b3595ae --- /dev/null +++ b/plugins/cdk/cdk.plugin.zsh @@ -0,0 +1,46 @@ +# Autocompletion for the AWS CDK CLI. +# +# AWS CDK supports generating its own zsh completion script via +# `cdk --completion`. This plugin caches that output and refreshes +# it asynchronously on each shell start, following the same pattern +# used by the argocd and helm plugins. + +if (( ! $+commands[cdk] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `cdk`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_cdk" ]]; then + typeset -g -A _comps + autoload -Uz _cdk + _comps[cdk]=_cdk +fi + +cdk --completion zsh >| "$ZSH_CACHE_DIR/completions/_cdk" &| + +# ── Aliases ────────────────────────────────────────────────────────────────── + +# Core workflow +alias cdkl='cdk list' +alias cdkls='cdk ls' +alias cdks='cdk synth' +alias cdkd='cdk deploy' +alias cdkda='cdk deploy --all' +alias cdkdiff='cdk diff' +alias cdkdes='cdk destroy' +alias cdkdesa='cdk destroy --all' +alias cdkw='cdk watch' +alias cdkb='cdk bootstrap' + +# Faster deploys +alias cdkdf='cdk deploy --require-approval never' +alias cdkdaf='cdk deploy --all --require-approval never' +alias cdkho='cdk deploy --hotswap' + +# Metadata / diagnostics +alias cdkdoc='cdk doctor' +alias cdkmeta='cdk metadata' +alias cdkctx='cdk context' +alias cdkctxr='cdk context --reset' +alias cdkack='cdk acknowledge'