From 8241da824054d9257e11b7268c46d0deab3f7808 Mon Sep 17 00:00:00 2001 From: pjaudiomv <34245618+pjaudiomv@users.noreply.github.com> Date: Sat, 23 Dec 2023 14:20:47 -0500 Subject: [PATCH] add autocomplete (#15) --- .github/workflows/pull-request.yml | 10 +++++----- .github/workflows/release.yml | 10 +++++----- CHANGELOG.md | 3 +++ Makefile | 2 ++ README.md | 12 +++++++++--- scripts/_awsd_autocomplete | 9 +++++++++ src/cmd/version.go | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100755 scripts/_awsd_autocomplete diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 10f4bf0..f38237b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,8 +11,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.19' - - name: Lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 - golangci-lint run main.go + go-version: '1.21' + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca232e3..757695a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,11 +11,11 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.19' - - name: Lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 - golangci-lint run main.go + go-version: '1.21' + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 release: runs-on: ubuntu-22.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index cdf9494..edc0667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.0.8 (December 23, 2023) +* Added autocomplete script to install. + ## v0.0.7 (October 20, 2023) * Update for new organization. diff --git a/Makefile b/Makefile index b8be740..131c217 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ help: ## Show this help install: ## Install Target GOOS= GOARCH= GOARM= GOFLAGS= go build -o ${BINDIR}/_awsd_prompt cp scripts/_awsd ${BINDIR}/_awsd + cp scripts/_awsd_autocomplete ${BINDIR}/_awsd_autocomplete @echo " -=-=--=-=-=-=-=-=-=-=-=-=-=-=- " @echo " " @echo " To Finish Installation add " @@ -20,4 +21,5 @@ install: ## Install Target uninstall: ## Uninstall Target rm -f ${BINDIR}/_awsd + rm -f ${BINDIR}/_awsd_autocomplete rm -f ${BINDIR}/_awsd_prompt diff --git a/README.md b/README.md index c6e03e4..449939c 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,8 @@ PROMPT='OTHER_PROMPT_STUFF $(aws_info)' ``` ## Add autocompletion -You can add autocompletion when passing profile as argument by creating a script with the following. I put it in -`~/bin/awsd_autocomplete.sh`, then source that script and add to your bash profile or zshrc file. -`source ~/bin/awsd_autocomplete.sh` +You can add autocompletion when passing config as argument by adding the following to your bash profile or zshrc file. +`source _awsd_autocomplete` ```bash [ "$BASH_VERSION" ] && AWSD_CMD="awsd" || AWSD_CMD="_awsd" @@ -96,6 +95,13 @@ complete -o nospace -F _awsd_completion "${AWSD_CMD}" Now you can do `awsd my-p` and hit tab and if you had a profile `my-profile` it would autocomplete and find it. +## TL;DR (full config example) +```bash +alias awsd="source _awsd" +source _awsd_autocomplete +export AWS_PROFILE=$(cat ~/.awsd) +``` + ## Contributing If you encounter any issues or have suggestions for improvements, please open an issue or create a pull request on [GitHub](https://github.com/radiusmethod/awsd). diff --git a/scripts/_awsd_autocomplete b/scripts/_awsd_autocomplete new file mode 100755 index 0000000..e00fa64 --- /dev/null +++ b/scripts/_awsd_autocomplete @@ -0,0 +1,9 @@ + +[ "$BASH_VERSION" ] && AWSD_CMD="awsd" || AWSD_CMD="_awsd" +_awsd_completion() { + local cur=${COMP_WORDS[COMP_CWORD]} + local suggestions=$(awsd list) + COMPREPLY=($(compgen -W "$suggestions" -- $cur)) + return 0 +} +complete -o nospace -F _awsd_completion "${AWSD_CMD}" diff --git a/src/cmd/version.go b/src/cmd/version.go index 5004fd5..018f9d2 100644 --- a/src/cmd/version.go +++ b/src/cmd/version.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" ) -var version string = "v0.0.7" +var version string = "v0.0.8" var versionCmd = &cobra.Command{ Use: "version",