Skip to content

Commit

Permalink
✨feat: allow directly passing profile as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlkrs committed Aug 7, 2023
1 parent c8d6cce commit 982086b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
15 changes: 8 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ builds:
- arm
- arm64
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- id: binary
name_template: >-
{{- .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end -}}
format_overrides:
- goos: windows
format: zip
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,38 @@
3. `cd scripts`
4. `sh ./install.sh`
5. Add an alias to your shell configuration (.bshrc, .zshrc, etc.)
```bash
alias awsp="source _awsp"
```
This is required so no additional shell has to be created.
```bash
alias awsp="source _awsp"
```
This is required so no additional shell has to be created.

## Usage

```shell
Supplying no argument will open the interactive
prompt.

```bash
$ awsp
```

Alternatively you can also directly pass a
profile to search for as an argument. The profile
that matches the argument the most using the Levinsthein
algorithm will be set.
If no profile is found, the prompt opens.

```bash
$ awsp client-proj
```

## Uninstall

In the release archive, there's an uninstall script
1. `cd scripts`
2. `sh ./uninstall.sh`
3. Remove the alias from your shell configuration file.
### Special thanks
The `alias awsp="source _awsp"` idea comes straight from [johnnyopao/awsp](https://github.com/johnnyopao/awsp). It's a very similar tool, however we really wanted fuzzy search :)
The `alias awsp="source _awsp"` idea comes straight from [johnnyopao/awsp](https://github.com/johnnyopao/awsp). It's a very similar tool, however we really wanted fuzzy search :)
30 changes: 26 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"log"
"os"

"github.com/lithammer/fuzzysearch/fuzzy"

"github.com/manifoldco/promptui"
)

var version string = "v1.0.9"
var version string = "v1.1.0"

func main() {
profiles, err := parseProfiles()
Expand All @@ -18,16 +19,37 @@ func main() {
return
}

templates := &promptui.SelectTemplates{
Active: `{{ "> " | cyan | bold }}{{ . | cyan | bold }}`,
Inactive: ` {{ . }}`,
/**
* In case the user already provided a profile
* to search for in the command line arguments,
* try to set it without using the prompt.
*/
if len(os.Args) > 1 {
argument := os.Args[1]

matchingProfiles := fuzzy.RankFind(argument, profiles)

if matchingProfiles.Len() > 0 {
setProfile(matchingProfiles[0].Target)
return
}
}

/**
* In case no profile could be found,
* or no argument has been provided,
* open the prompt.
*/
searcher := func(input string, index int) bool {
item := profiles[index]
return fuzzy.MatchFold(input, item)
}

templates := &promptui.SelectTemplates{
Active: `{{ "> " | cyan | bold }}{{ . | cyan | bold }}`,
Inactive: ` {{ . }}`,
}

prompt := promptui.Select{
Label: "Select AWS Profile",
Items: profiles,
Expand Down
2 changes: 1 addition & 1 deletion scripts/profile-exporter.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

aws-profile-picker
aws-profile-picker $@

selected_profile="$(cat $HOME/.aws-profile-picker)"

Expand Down

0 comments on commit 982086b

Please sign in to comment.