Skip to content

Instantly share code, notes, and snippets.

@chrisortman
Last active April 15, 2019 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisortman/1c6e3646ed36724bc6d15bb4eb224d89 to your computer and use it in GitHub Desktop.
Save chrisortman/1c6e3646ed36724bc6d15bb4eb224d89 to your computer and use it in GitHub Desktop.
Shell stuff for putting AWS context in my prompt (make sure jq is on your path)
if .Account == "9999999" then "test" elif .Account == "111111" then "prod" else "" end
aws_prompt_info () {
local PID_FILE=~/.aws-login/default.pid
local IDENTITY_FILE=~/.aws-login/identity.txt
local FILTER_FILE=~/.oh-my-zsh/custom/aws_filter.jq
local PROF=""
if [[ -f "$PID_FILE" ]]
then
PROF=$( cat "$IDENTITY_FILE" 2>/dev/null || aws sts get-caller-identity | jq -r -f "$FILTER_FILE" | tee "$IDENTITY_FILE")
[[ -n "$PROF" ]] && echo "[$PROF]"
else
[[ -f "$IDENTITY_FILE" ]] && rm "$IDENTITY_FILE"
fi
}
# Depending on what you're using for a shell this will probably be different. In my shell I have my name instead of dude in case I forget it again
HOST_PROMPT_='%{$fg_bold[red]%}@dude$(aws_prompt_info) %{$fg_bold[cyan]%}%c '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment