romkatv / powerlevel10k

A Zsh theme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add AWS Current Account ID & Alias to p10k Prompt

rilwansogbesan opened this issue · comments

Hello,

Forgive me if this has been covered somewhere but I'm at a loss.

I love the powerlevel10k theme.

I currently use it in a work environment where most of our accounts are accessible via SSO and assumeroles. So I only technically have 1 profile in my AWS Credentials file so the AWS plugin doesn't really do me any good.

I've written 2 really basic functions that gimme what I need. One that gets the AWS Account ID and the other that gets the Account's alias.

function awsacctid() 
{ 
   # Print the current, active AWS account id

   acct_id=$(aws sts get-caller-identity | jq -r '.Account' | tr -d '\n')
   echo -n "${acct_id}"
}
function awsacctalias
{
   # Print the current, active AWS account alias 

   acct_alias=$(aws iam list-account-aliases | jq -r '.AccountAliases[]' | tr -d '\n')
   echo -n "${acct_alias}"
}

All I haven't been able to figure out is how to get this to show in my terminal prompt.

Screenshot 2024-03-21 at 5 17 53 PM

I basically wanna see the account ID and alias on the left after my current dir. What's displayed on the right isn't accurate enough for me.

Any and all help is greatly appreciated.

If you want to display custom info in prompt, you need a custom prompt segment. Search for "prompt_example" in ~/.p10k.zsh and see p10k help segment.