Skip to content

Instantly share code, notes, and snippets.

@pysysops
Last active October 26, 2023 09:52
Show Gist options
  • Save pysysops/b0fd78aa52629f321034289af042be24 to your computer and use it in GitHub Desktop.
Save pysysops/b0fd78aa52629f321034289af042be24 to your computer and use it in GitHub Desktop.
Powerlevel10k custom prompt config for use with aws-vault https://github.com/99designs/aws-vault
##############[ custom_awsvault: current aws account (https://github.com/99designs/aws-vault) ]###############
awsvault_prompt() {
if [ ! -z "${AWS_VAULT-}" ]; then
echo -n " ${AWS_VAULT-} "
fi
}
typeset -g POWERLEVEL9K_CUSTOM_AWSVAULT="awsvault_prompt"
typeset -g POWERLEVEL9K_CUSTOM_AWSVAULT_FOREGROUND="black"
typeset -g POWERLEVEL9K_CUSTOM_AWSVAULT_BACKGROUND="yellow"
typeset -g POWERLEVEL9K_CUSTOM_AWSVAULT_VISUAL_IDENTIFIER_EXPANSION=' ☁️'
@pysysops
Copy link
Author

pysysops commented Sep 10, 2019

I use aws-vault to move around AWS accounts and assume roles within the accounts I work with. I use Powerlevel10k (https://github.com/romkatv/powerlevel10k) to customize my zsh shell.

There's a few occasions when I've run a Terraform plan or being searching for some answer in the wrong account. The above custom prompt code will help you to avoid that by making the current account you're "in".

Add the code in this gist and add a reference to the prompt wherever you'd like it to appear:

typeset -g POWERLEVEL9K_(LEFT OR RIGHT)_PROMPT_ELEMENTS=(
    ....
    custom_awsvault
    ....
)

Example:
Screenshot 2019-09-10 at 09 38 01

@zmingxie
Copy link

Hello @pysysops, I was brought to this gist when I googled "powerlevel10k aws-vault" earlier. 😄

However, I can't seem to get this custom prompt working, and I'm curious if it's because I'm running aws-vault v6.1.0.

If you have a moment, could you confirm which version of aws-vault you are using? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment