Code Monkey home page Code Monkey logo

awsd's Introduction

awsd - AWS Profile Switcher in Go

awsd is a command-line utility that allows you to easily switch between AWS Profiles

Installation

Make sure you have Go installed. You can download it from here.

Homebrew

brew tap radiusmethod/awsd
brew install awsd

Makefile

make install

To Finish Installation

Add the following to your bash profile or zshrc then open new terminal or source that file

alias awsd="source _awsd"

Ex. echo 'alias awsd="source _awsd"' >> ~/.zshrc

Usage

Switching AWS Profiles

It is possible to shortcut the menu selection by passing the profile name you want to switch to as an argument.

> awsd work
Profile work set.

To switch between different profiles files using the menu, use the following command:

awsd

This command will display a list of available profiles files in your ~/aws/config file. Select the one you want to use.

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.

export AWS_PROFILE=$(cat ~/.awsd)

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.

Here's a sample of my zsh prompt config using oh-my-zsh themes

# AWS info
local aws_info='$(aws_prof)'
function aws_prof {
  local profile="${AWS_PROFILE:=}"
  echo -n "%{$fg_bold[blue]%}aws:(%{$fg[cyan]%}${profile}%{$fg_bold[blue]%})%{$reset_color%} "
}
PROMPT='OTHER_PROMPT_STUFF $(aws_info)'

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

[ "$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}"

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)

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Inspired by https://github.com/johnnyopao/awsp

awsd's People

Contributors

pjaudiomv avatar renovate[bot] avatar m1kep avatar withakay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.