diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4c3ec4..cb5eaf3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,12 @@
+## v0.1.1 (June 28, 2024)
+* Replaced regular expressions with the `ini` package for extracting profiles from AWS config files.
+* Fixed an issue where extra spaces between the "profile" keyword and the profile name could prevent the profile from being set.
+
## v0.1.0 (May 2, 2024)
-* Increase zsh autocompletion compatibilty.
+* Increase zsh autocompletion compatibility.
## v0.0.9 (April 4, 2024)
-* Fixes issue with help command shorthand flag `-h`. [#20] thanks @Masamerc
+* Fixes issue with help command shorthand flag `-h`. [#20] thanks, @Masamerc
## v0.0.8 (December 23, 2023)
* Added autocomplete script to install.
@@ -14,7 +18,7 @@
* Refactored codebase.
## v0.0.5 (October 6, 2023)
-* Added support for passing arbitrary profile names as arguments. [#4] thanks @withakay
+* Added support for passing arbitrary profile names as arguments. [#4] thanks, @withakay
* Added `awsd list` command to simply list all profiles.
## v0.0.4 (October 4, 2023)
@@ -24,7 +28,7 @@
* Added additional error checking.
## v0.0.2 (May 27, 2022)
-* Added ability to search AWS profiles. [#4] thanks @M1kep
+* Added ability to search AWS profiles. [#4] thanks, @M1kep
## v0.0.1 (November 30, 2021)
* Initial Release
diff --git a/README.md b/README.md
index 449939c..fc9dfb6 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,28 @@
# awsd - AWS Profile Switcher in Go
+---
+
-awsd is a command-line utility that allows you to easily switch between AWS Profiles
+awsd is a command-line utility that allows you to easily switch between AWS Profiles.
+## Table of Contents
+
+- [Installation](#installation)
+ - [Homebrew](#homebrew)
+ - [Makefile](#makefile)
+ - [To Finish Installation](#to-finish-installation)
+- [Usage](#usage)
+ - [Switching AWS Profiles](#switching-aws-profiles)
+ - [Persist Profile across new shells](#persist-profile-across-new-shells)
+ - [Show your AWS Profile in your shell prompt](#show-your-aws-profile-in-your-shell-prompt)
+ - [Add autocompletion](#add-autocompletion)
+ - [TL;DR (full config example)](#tldr-full-config-example)
+- [Contributing](#contributing)
+- [License](#license)
+
## Installation
Make sure you have Go installed. You can download it from [here](https://golang.org/dl/).
@@ -49,16 +66,17 @@ To switch between different profiles files using the menu, use the following com
awsd
```
-This command will display a list of available profiles files in your `~/aws/config` file. Select the one you want to use.
+This command will display a list of available profiles files in your `~/.aws/config` file or from `AWS_CONFIG_FILE`
+if you have that set. It expects for you to have named profiles in your AWS config file. Select the one you want to use.
-## Persist Profile across new shells
+### Persist Profile across new shells
To persist the set profile when you open new terminal windows, you can add the following to your bash profile or zshrc.
```bash
export AWS_PROFILE=$(cat ~/.awsd)
```
-## Show your AWS Profile in your shell prompt
+### Show your AWS Profile in your shell prompt
For better visibility into what your shell is set to it can be helpful to configure your prompt to show the value of the env variable `AWS_PROFILE`.
@@ -78,7 +96,7 @@ function aws_prof {
PROMPT='OTHER_PROMPT_STUFF $(aws_info)'
```
-## Add autocompletion
+### Add autocompletion
You can add autocompletion when passing config as argument by adding the following to your bash profile or zshrc file.
`source _awsd_autocomplete`
@@ -95,7 +113,7 @@ 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)
+### TL;DR (full config example)
```bash
alias awsd="source _awsd"
source _awsd_autocomplete
diff --git a/go.mod b/go.mod
index 406fd67..8251494 100644
--- a/go.mod
+++ b/go.mod
@@ -12,4 +12,5 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.12.0 // indirect
+ gopkg.in/ini.v1 v1.67.0 // indirect
)
diff --git a/go.sum b/go.sum
index 62134d5..e5e4e2c 100644
--- a/go.sum
+++ b/go.sum
@@ -28,4 +28,6 @@ golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/renovate.json b/renovate.json
index 39a2b6e..787495d 100644
--- a/renovate.json
+++ b/renovate.json
@@ -1,6 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
- "config:base"
+ "config:recommended"
+ ],
+ "schedule": ["after 8am on Tuesday"],
+ "packageRules": [
+ {
+ "updateTypes": ["major", "minor", "patch"],
+ "schedule": ["after 8am on Tuesday"]
+ }
]
}
diff --git a/src/cmd/version.go b/src/cmd/version.go
index 2079b08..1b2c251 100644
--- a/src/cmd/version.go
+++ b/src/cmd/version.go
@@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)
-var version string = "v0.1.0"
+var version string = "v0.1.1"
var versionCmd = &cobra.Command{
Use: "version",
diff --git a/src/utils/aws.go b/src/utils/aws.go
index b30c320..d8e7087 100644
--- a/src/utils/aws.go
+++ b/src/utils/aws.go
@@ -1,44 +1,33 @@
package utils
import (
- "bufio"
+ "gopkg.in/ini.v1"
"log"
- "os"
- "regexp"
"sort"
+ "strings"
+)
+
+const (
+ profilePrefix = "profile"
+ defaultProfile = "default"
)
func GetProfiles() []string {
profileFileLocation := GetCurrentProfileFile()
- profiles := make([]string, 0)
-
- file, err := os.Open(profileFileLocation)
+ cfg, err := ini.Load(profileFileLocation)
if err != nil {
- log.Fatal(err)
+ log.Fatalf("Failed to load profiles: %v", err)
}
- defer file.Close()
-
- scanner := bufio.NewScanner(file)
- r, err := regexp.Compile(`\[profile .*]`)
-
- if err != nil {
- log.Fatal(err)
- }
-
- for scanner.Scan() {
- if r.MatchString(scanner.Text()) {
- s := scanner.Text()
- reg := regexp.MustCompile(`(\[profile )|(])`)
- res := reg.ReplaceAllString(s, "")
- profiles = append(profiles, res)
+ sections := cfg.SectionStrings()
+ profiles := make([]string, 0, len(sections)+1)
+ for _, section := range sections {
+ if strings.HasPrefix(section, profilePrefix) {
+ trimmedProfile := strings.TrimPrefix(section, profilePrefix)
+ trimmedProfile = strings.TrimSpace(trimmedProfile)
+ profiles = append(profiles, trimmedProfile)
}
}
-
- if err := scanner.Err(); err != nil {
- log.Fatal(err)
- }
-
- profiles = AppendIfNotExists(profiles, "default")
+ profiles = AppendIfNotExists(profiles, defaultProfile)
sort.Strings(profiles)
return profiles
}