Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage.*
# Dependency directories (remove the comment below to include it)
# vendor/
bin/
tools/gendocs/gendocs
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.2.0 (April 27, 2026)
* Added region switching: `awsd set region [name]` (interactive picker if no name given), `awsd unset region`, `awsd list regions`.
* Added `awsd set profile [name]` and `awsd unset profile` as explicit forms — bare `awsd <profile>` still works.
* `~/.awsd` now uses a `key=value` format (`profile=...` / `region=...`). Legacy single-line files are still readable; the next write upgrades them.
* Wrapper now also exports `AWS_DEFAULT_REGION` alongside `AWS_REGION`.

## v0.1.3 (March 9, 2025)
* Adds circular scrolling

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ uninstall: ## Uninstall Target
rm -f ${BINDIR}/_awsd_autocomplete
rm -f ${BINDIR}/_awsd_prompt

.PHONY: test test-coverage
.PHONY: test test-coverage docs
test: ## Run tests
go test ./...

docs: ## Regenerate docs/*.md from the cobra command tree
cd tools/gendocs && go run . ../../docs

test-coverage: ## Run tests with coverage report
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
6 changes: 4 additions & 2 deletions docs/awsd.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ awsd [flags]

### SEE ALSO

* [awsd list](awsd_list.md) - List AWS profiles command.
* [awsd list](awsd_list.md) - List AWS profiles or regions.
* [awsd set](awsd_set.md) - Set the active AWS profile or region.
* [awsd unset](awsd_unset.md) - Unset the active AWS profile or region.
* [awsd version](awsd_version.md) - awsd version command

###### Auto generated by spf13/cobra on 6-Oct-2023
###### Auto generated by spf13/cobra on 27-Apr-2026
8 changes: 4 additions & 4 deletions docs/awsd_list.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## awsd list

List AWS profiles command.
List AWS profiles or regions.

### Synopsis

This lists all your AWS profiles.
List all your AWS profiles, or the known AWS regions. Defaults to profiles.

```
awsd list [flags]
awsd list [profiles|regions] [flags]
```

### Options
Expand All @@ -20,4 +20,4 @@ awsd list [flags]

* [awsd](awsd.md) - awsd - switch between AWS profiles.

###### Auto generated by spf13/cobra on 6-Oct-2023
###### Auto generated by spf13/cobra on 27-Apr-2026
21 changes: 21 additions & 0 deletions docs/awsd_set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## awsd set

Set the active AWS profile or region.

### Synopsis

Set the active AWS profile or region. With no subcommand, prints help.

### Options

```
-h, --help help for set
```

### SEE ALSO

* [awsd](awsd.md) - awsd - switch between AWS profiles.
* [awsd set profile](awsd_set_profile.md) - Set the active AWS profile (interactive picker if no name given).
* [awsd set region](awsd_set_region.md) - Set the active AWS region (interactive picker if no region given).

###### Auto generated by spf13/cobra on 27-Apr-2026
19 changes: 19 additions & 0 deletions docs/awsd_set_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## awsd set profile

Set the active AWS profile (interactive picker if no name given).

```
awsd set profile [name] [flags]
```

### Options

```
-h, --help help for profile
```

### SEE ALSO

* [awsd set](awsd_set.md) - Set the active AWS profile or region.

###### Auto generated by spf13/cobra on 27-Apr-2026
19 changes: 19 additions & 0 deletions docs/awsd_set_region.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## awsd set region

Set the active AWS region (interactive picker if no region given).

```
awsd set region [region] [flags]
```

### Options

```
-h, --help help for region
```

### SEE ALSO

* [awsd set](awsd_set.md) - Set the active AWS profile or region.

###### Auto generated by spf13/cobra on 27-Apr-2026
21 changes: 21 additions & 0 deletions docs/awsd_unset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## awsd unset

Unset the active AWS profile or region.

### Synopsis

Clear the active AWS profile (back to default) or AWS region.

### Options

```
-h, --help help for unset
```

### SEE ALSO

* [awsd](awsd.md) - awsd - switch between AWS profiles.
* [awsd unset profile](awsd_unset_profile.md) - Reset the active AWS profile to default.
* [awsd unset region](awsd_unset_region.md) - Clear the active AWS region.

###### Auto generated by spf13/cobra on 27-Apr-2026
19 changes: 19 additions & 0 deletions docs/awsd_unset_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## awsd unset profile

Reset the active AWS profile to default.

```
awsd unset profile [flags]
```

### Options

```
-h, --help help for profile
```

### SEE ALSO

* [awsd unset](awsd_unset.md) - Unset the active AWS profile or region.

###### Auto generated by spf13/cobra on 27-Apr-2026
19 changes: 19 additions & 0 deletions docs/awsd_unset_region.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## awsd unset region

Clear the active AWS region.

```
awsd unset region [flags]
```

### Options

```
-h, --help help for region
```

### SEE ALSO

* [awsd unset](awsd_unset.md) - Unset the active AWS profile or region.

###### Auto generated by spf13/cobra on 27-Apr-2026
2 changes: 1 addition & 1 deletion docs/awsd_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ awsd version [flags]

* [awsd](awsd.md) - awsd - switch between AWS profiles.

###### Auto generated by spf13/cobra on 6-Oct-2023
###### Auto generated by spf13/cobra on 27-Apr-2026
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/radiusmethod/awsd
go 1.23.5

require (
github.com/radiusmethod/promptui v0.10.3
github.com/radiusmethod/promptui v0.11.0
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
gopkg.in/ini.v1 v1.67.1
Expand All @@ -15,6 +15,6 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/sys v0.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/radiusmethod/promptui v0.10.3 h1:JeayJuCR/bPvZp5cGqd+sAk4NDZG9CCt0vBVTFIiCo8=
github.com/radiusmethod/promptui v0.10.3/go.mod h1:DYozY3lsgSlf+M+LXX4QF7/QY246KqP69zhdIvPBg+8=
github.com/radiusmethod/promptui v0.11.0 h1:IUP99vU3WgzIrAKicJ1ZwyTFEdTSsa9B6DUbv6GS0HA=
github.com/radiusmethod/promptui v0.11.0/go.mod h1:w+XRl9+IuUv5Fvf/notZrM5mkyagzVCxEiNnyplHYA0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
Expand All @@ -30,8 +30,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
Expand Down
34 changes: 31 additions & 3 deletions scripts/_awsd
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,39 @@ else
fi

touch ~/.awsd
selected_profile="$(cat ~/.awsd)"

if [ -z "$selected_profile" ]
unset _awsd_profile _awsd_region _awsd_has_region

# Detect legacy single-line format (no '=' anywhere): whole file is a profile name.
if grep -q '=' ~/.awsd
then
while IFS='=' read -r _awsd_k _awsd_v
do
case "$_awsd_k" in
profile) _awsd_profile=$_awsd_v ;;
region) _awsd_region=$_awsd_v; _awsd_has_region=1 ;;
esac
done < ~/.awsd
else
_awsd_profile="$(cat ~/.awsd)"
fi

if [ -z "$_awsd_profile" ]
then
unset AWS_PROFILE
else
export AWS_PROFILE="$selected_profile"
export AWS_PROFILE="$_awsd_profile"
fi

if [ -n "$_awsd_has_region" ]
then
if [ -z "$_awsd_region" ]
then
unset AWS_REGION AWS_DEFAULT_REGION
else
export AWS_REGION="$_awsd_region"
export AWS_DEFAULT_REGION="$_awsd_region"
fi
fi

unset _awsd_profile _awsd_region _awsd_has_region _awsd_k _awsd_v
29 changes: 28 additions & 1 deletion scripts/_awsd_autocomplete
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,34 @@
[ "$BASH_VERSION" ] && AWSD_CMD="awsd" || AWSD_CMD="_awsd"
_awsd_completion() {
local cur=${COMP_WORDS[COMP_CWORD]}
local suggestions=$(awsd list)
local prev=${COMP_WORDS[COMP_CWORD-1]}
local subcmd=${COMP_WORDS[1]}
local suggestions

case "$COMP_CWORD" in
1)
# awsd <TAB> — profiles + top-level subcommands
suggestions="$(awsd list profiles) list set unset"
;;
2)
case "$subcmd" in
set|unset) suggestions="profile region" ;;
list|l) suggestions="profiles regions" ;;
*) suggestions="" ;;
esac
;;
3)
case "$subcmd $prev" in
"set profile") suggestions="$(awsd list profiles)" ;;
"set region") suggestions="$(awsd list regions)" ;;
*) suggestions="" ;;
esac
;;
*)
suggestions=""
;;
esac

COMPREPLY=($(compgen -W "$suggestions" -- $cur))
return 0
}
Expand Down
43 changes: 40 additions & 3 deletions scripts/powershell/awsd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,50 @@ else
awsd_prompt $args
}

$selected_profile = Get-Content "$env:USERPROFILE\.awsd"
$awsd_profile = $null
$awsd_region = $null
$awsd_has_region = $false

if (-not $selected_profile)
if (Test-Path "$env:USERPROFILE\.awsd")
{
$lines = Get-Content "$env:USERPROFILE\.awsd"
$hasKV = $false
foreach ($line in $lines) {
if ($line -match '=') { $hasKV = $true; break }
}

if ($hasKV) {
foreach ($line in $lines) {
if ($line -match '^\s*([^=]+?)\s*=\s*(.*)$') {
$key = $Matches[1]
$val = $Matches[2].Trim()
switch ($key) {
'profile' { $awsd_profile = $val }
'region' { $awsd_region = $val; $awsd_has_region = $true }
}
}
}
} else {
# Legacy single-line format: whole file is a profile name.
$awsd_profile = ($lines | Out-String).Trim()
}
}

if (-not $awsd_profile)
{
$env:AWS_PROFILE = $null
}
else
{
$env:AWS_PROFILE = $selected_profile
$env:AWS_PROFILE = $awsd_profile
}

if ($awsd_has_region) {
if (-not $awsd_region) {
$env:AWS_REGION = $null
$env:AWS_DEFAULT_REGION = $null
} else {
$env:AWS_REGION = $awsd_region
$env:AWS_DEFAULT_REGION = $awsd_region
}
}
Loading