This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,52 +1,92 @@ | ||
# AWSP Plus - Upgraded AWS Profile Switcher | ||
|
||
Easily switch between AWS Profiles | ||
Easily switch between AWS Profiles. | ||
|
||
Expanded fork of [awsp by johnnyopao](https://github.com/johnnyopao/awsp) with additional features and ongoing maintenance.* | ||
|
||
\* best attempt will be made to regularly maintain, but no guarantee is provided. | ||
|
||
<img src="demo.gif" width="500"> | ||
|
||
## Prereqs | ||
Setup your profiles using the aws cli | ||
## How it works | ||
|
||
The AWS CLI will use the profile present in the `AWS_PROFILE` environment variable, if no flag is set. This script parses the current aws profiles (`~/.aws/config`) and provides a filterable list, and then sets the environment variable based on the selection. | ||
|
||
## Prerequisites | ||
Setup any number of profiles using the aws cli. | ||
|
||
```sh | ||
aws configure --profile PROFILE_NAME | ||
``` | ||
|
||
You can also leave out the `--profile PROFILE_NAME` param to set your `default` credentials | ||
|
||
Refer to this doc for more information | ||
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html | ||
Refer to the AWS CLI Documentation for more information: | ||
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html | ||
|
||
## Setup | ||
|
||
```sh | ||
npm install -g awsp | ||
npm install -g awsp-plus | ||
``` | ||
|
||
Add the following to your `.bashrc` or `.zshrc` config | ||
Add the following line to your `.bashrc` or `.zshrc` config: | ||
```sh | ||
alias awsp="source _awsp" | ||
alias awsp="source _awspp" | ||
``` | ||
|
||
> An alias is used because `_awspp` needs to be sourced to be able to modify the calling shell's environment variables. | ||
## Usage | ||
Standard usage is just to call `awsp` and select a profile: | ||
```sh | ||
awsp | ||
``` | ||
You can type to filter the list, or arrow through the shown options. Press \<Enter\> to select the highlighted option. | ||
|
||
You can also type a profile with the command to immediately switch: | ||
```sh | ||
awsp development | ||
``` | ||
This is equivalent to `export AWS_PROFILE='development'`. | ||
|
||
## Show your AWS Profile in your shell prompt | ||
For better visibility into what your shell is set to it's helpful to configure your prompt to show the value of the env variable `AWS_PROFILE`. | ||
## Recommendation: Show your AWS Profile in your shell prompt | ||
For better visibility into what AWS Profile is selected it's helpful to configure your prompt to show the value of the env variable `AWS_PROFILE`. | ||
|
||
<img src="screenshot.png" width="300"> | ||
|
||
Here's a sample of my zsh prompt config using oh-my-zsh themes | ||
|
||
### Examples | ||
Here is a simplified example: | ||
```sh | ||
function aws_prof { | ||
local profile="${AWS_PROFILE:=default}" | ||
|
||
echo "%{$fg_bold[blue]%}aws:(%{$fg[yellow]%}${profile}%{$fg_bold[blue]%})%{$reset_color%} " | ||
echo "aws:(${profile})" | ||
} | ||
|
||
PS1="$PS1 \$(aws_prof)" | ||
``` | ||
|
||
Here's Johnny's example using oh-my-zsh themes, with nice colors: | ||
|
||
```sh | ||
function aws_prof { | ||
local profile="${AWS_PROFILE:=default}" | ||
|
||
echo "%{$fg_bold[blue]%}aws:(%{$fg[yellow]%}${profile}%{$fg_bold[blue]%})%{$reset_color%} " | ||
} | ||
|
||
PROMPT='OTHER_PROMPT_STUFF $(aws_prof)' | ||
``` | ||
|
||
A more advanced example for bash can be found in my dotfiles at [https://github.com/abyss/dotfiles](https://github.com/abyss/dotfiles/blob/main/bin/aws-prompt.sh). | ||
|
||
## Contributing | ||
Issues and pull requests are welcome. 😄 | ||
|
||
## License | ||
This project and the original work are licensed under the [ISC License](LICENSE.md). | ||
|
||
Copyright (c) 2021 Abyss | ||
|
||
Original Work Copyright (c) 2020 Johnny Opao (@ https://github.com/johnnyopao/awsp) |