-
Notifications
You must be signed in to change notification settings - Fork 617
feat(aws-cli): 🧑💻 add aws-cli completion #1083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Samruddhi Khandale (samruddhikhandale)
merged 10 commits into
devcontainers:main
from
rubensa:aws-cli-completion
Aug 28, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31163e1
feat(aws-cli): 🧑💻 add aws completion
rubensa 2d5f803
test(aws-cli): ✅ test aws bash completion
rubensa 3467a01
chore(aws-cli): 🔧 update feature version
rubensa 8b0e1b8
fix(aws-cli): cp command fix
rubensa 51731da
refactor(aws-cli): move vendor scripts to specific folder
rubensa bc81c73
docs(aws-cli): add README to vendor scripts
rubensa 48f18b9
build(aws-cli): automate aws-cli vendor completer scripts updates
rubensa d312e07
chore(aws-cli): update vendor completer scripts
rubensa 034ca5f
build(aws-cli): update message
rubensa aab9584
chore(aws-cli): remove some code remainders
rubensa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: "Updates vendor 'aws_bash_completer' and 'aws_zsh_completer.sh' scripts" | ||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: '0 0 * * 0' # Runs every Sunday at midnight UTC (adjust as needed) | ||
|
|
||
| jobs: | ||
| fetch-latest-aws-completer-scripts: | ||
| runs-on: ubuntu-latest | ||
| environment: documentation # grants access to secrets.PAT, for creating pull requests | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Run fetch-latest-completer-scripts.sh | ||
| run: src/aws-cli/scripts/fetch-latest-completer-scripts.sh | ||
|
|
||
| - name: Create a PR for completer scripts | ||
| id: push_image_info | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.PAT }} | ||
| run: | | ||
| set -e | ||
| echo "Start." | ||
|
|
||
| # Configure git and Push updates | ||
| git config --global user.email github-actions@github.com | ||
| git config --global user.name github-actions | ||
| git config pull.rebase false | ||
|
|
||
| branch=automated-script-update-$GITHUB_RUN_ID | ||
| git checkout -b $branch | ||
| message='[Updates] Automated vendor 'aws-cli' completer scripts' | ||
|
|
||
| # Add / update and commit | ||
| git add src/aws-cli/scripts/vendor/aws_bash_completer | ||
| git add src/aws-cli/scripts/vendor/aws_zsh_completer.sh | ||
|
|
||
| git commit -m 'Automated completer scripts update' || export NO_UPDATES=true | ||
|
|
||
| # Bump version and push | ||
| if [ "$NO_UPDATES" != "true" ] ; then | ||
| echo "$(jq --indent 4 '.version = (.version | split(".") | map(tonumber) | .[2] += 1 | join("."))' src/aws-cli/devcontainer-feature.json)" > src/aws-cli/devcontainer-feature.json | ||
| git add src/aws-cli/devcontainer-feature.json | ||
|
|
||
| git commit -m 'Bump version' | ||
| git push origin "$branch" | ||
| gh api \ | ||
| --method POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| /repos/${GITHUB_REPOSITORY}/pulls \ | ||
| -f title="$message" \ | ||
| -f body="$message" \ | ||
| -f head="$branch" \ | ||
| -f base="$GITHUB_REF_NAME" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
| #------------------------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
| #------------------------------------------------------------------------------------------------------------- | ||
| # | ||
| # Docs: https://github.com/devcontainers/features/tree/main/src/aws-cli | ||
| # Maintainer: The Dev Container spec maintainers | ||
| # | ||
| # Run this script to replace aws_bash_completer and aws_zsh_completer.sh with the latest and greatest available version | ||
| # | ||
| COMPLETER_SCRIPTS=$(dirname "${BASH_SOURCE[0]}") | ||
| BASH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_bash_completer" | ||
| ZSH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_zsh_completer.sh" | ||
|
|
||
| wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_bash_completer -O "$BASH_COMPLETER_SCRIPT" | ||
| chmod +x "$BASH_COMPLETER_SCRIPT" | ||
|
|
||
| wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_zsh_completer.sh -O "$ZSH_COMPLETER_SCRIPT" | ||
| chmod +x "$ZSH_COMPLETER_SCRIPT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ### **IMPORTANT NOTE** | ||
|
|
||
| Scripts in this directory are sourced externally and not maintained by the Dev Container spec maintainers. Do not make changes directly as they might be overwritten at any moment. | ||
|
|
||
| ## aws_bash_completer | ||
|
|
||
| `aws_bash_completer` is a copy of <https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_bash_completer>. | ||
|
|
||
| ## aws_zsh_completer.sh | ||
|
|
||
| `aws_zsh_completer.sh` is a copy of <https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_zsh_completer.sh>. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Typically that would be added under one of the following paths: | ||
| # - /etc/bash_completion.d | ||
| # - /usr/local/etc/bash_completion.d | ||
| # - /usr/share/bash-completion/completions | ||
|
|
||
| complete -C aws_completer aws |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Source this file to activate auto completion for zsh using the bash | ||
| # compatibility helper. Make sure to run `compinit` before, which should be | ||
| # given usually. | ||
| # | ||
| # % source /path/to/zsh_complete.sh | ||
| # | ||
| # Typically that would be called somewhere in your .zshrc. | ||
| # | ||
| # Note, the overwrite of _bash_complete() is to export COMP_LINE and COMP_POINT | ||
| # That is only required for zsh <= edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 | ||
| # | ||
| # https://github.com/zsh-users/zsh/commit/edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 | ||
| # | ||
| # zsh releases prior to that version do not export the required env variables! | ||
|
|
||
| autoload -Uz bashcompinit | ||
| bashcompinit -i | ||
|
|
||
| _bash_complete() { | ||
| local ret=1 | ||
| local -a suf matches | ||
| local -x COMP_POINT COMP_CWORD | ||
| local -a COMP_WORDS COMPREPLY BASH_VERSINFO | ||
| local -x COMP_LINE="$words" | ||
| local -A savejobstates savejobtexts | ||
|
|
||
| (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX )) | ||
| (( COMP_CWORD = CURRENT - 1)) | ||
| COMP_WORDS=( $words ) | ||
| BASH_VERSINFO=( 2 05b 0 1 release ) | ||
|
|
||
| savejobstates=( ${(kv)jobstates} ) | ||
| savejobtexts=( ${(kv)jobtexts} ) | ||
|
|
||
| [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' ) | ||
|
|
||
| matches=( ${(f)"$(compgen $@ -- ${words[CURRENT]})"} ) | ||
|
|
||
| if [[ -n $matches ]]; then | ||
| if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then | ||
| compset -P '*/' && matches=( ${matches##*/} ) | ||
| compset -S '/*' && matches=( ${matches%%/*} ) | ||
| compadd -Q -f "${suf[@]}" -a matches && ret=0 | ||
| else | ||
| compadd -Q "${suf[@]}" -a matches && ret=0 | ||
| fi | ||
| fi | ||
|
|
||
| if (( ret )); then | ||
| if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then | ||
| _default "${suf[@]}" && ret=0 | ||
| elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then | ||
| _directories "${suf[@]}" && ret=0 | ||
| fi | ||
| fi | ||
|
|
||
| return ret | ||
| } | ||
|
|
||
| complete -C aws_completer aws |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
samruddhikhandale marked this conversation as resolved.
|
||
|
|
||
| command=$1 | ||
| expected=$2 | ||
|
samruddhikhandale marked this conversation as resolved.
|
||
|
|
||
| echo -e "Checking completion for command '$command'..." | ||
|
|
||
| # Send command as a character stream, followed by two tab characters, into an interactive bash shell. | ||
| # Also note the 'y' which responds to the possible Bash question "Display all xxx possibilities? (y or n)". | ||
| # Bash produces the autocompletion output on stderr, so redirect that to stdout. | ||
| # The sed bit captures the lines between Header and Footer (used as output delimiters). | ||
| # The first grep removes the "Display all" message (that is atomatically answered to "y" by the script). | ||
| # The last grep filters the output to lines containing the expected result. | ||
| COMPLETE_OUTPUT=$(echo if false\; then "Header"\; $command$'\t'$'\t'y\; "Footer" fi | bash -i 2>&1 | sed -n '/Header/{:a;n;/Footer/q;p;ba}' | grep -v ^'Display all ') | ||
| echo -e "\nCompletion output:\n" | ||
| echo -e "$COMPLETE_OUTPUT" | ||
| echo -e "\n" | ||
|
|
||
| FILTERED_COMPLETE_OUTPUT=$(echo "$COMPLETE_OUTPUT" | grep "$expected") | ||
|
|
||
| if [ -z "$FILTERED_COMPLETE_OUTPUT" ]; then | ||
| echo -e "Completion output does not contains '$expected'." | ||
| exit 1 | ||
| else | ||
| echo -e "Completion output contains '$expected'." | ||
| exit 0 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.