Skip to content

Instantly share code, notes, and snippets.

@paulswail
Created August 10, 2021 11:11
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 paulswail/7857200a9e3ec8b122f3bba20aec1c02 to your computer and use it in GitHub Desktop.
Save paulswail/7857200a9e3ec8b122f3bba20aec1c02 to your computer and use it in GitHub Desktop.
ZSH prompt with Git and AWS profile status
# original script credit: https://github.com/holman/dotfiles
autoload colors && colors
if (( $+commands[git] ))
then
git="$commands[git]"
else
git="/usr/bin/git"
fi
git_branch() {
echo $($git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
git_dirty() {
if $(! $git status -s &> /dev/null)
then
echo ""
else
if [[ $($git status --porcelain) == "" ]]
then
echo "[%{$fg_bold[green]%}$(git_prompt_info)%{$reset_color%}]"
else
echo "[%{$fg_bold[red]%}$(git_prompt_info)%{$reset_color%}]"
fi
fi
}
git_prompt_info () {
ref=$($git symbolic-ref HEAD 2>/dev/null) || return
echo "${ref#refs/heads/}"
}
unpushed () {
$git cherry -v @{upstream} 2>/dev/null
}
need_push () {
if [[ $(unpushed) == "" ]]
then
echo " "
else
echo " with %{$fg_bold[magenta]%}unpushed%{$reset_color%} "
fi
}
aws_prompt() {
if [[ -n $AWS_PROFILE ]]; then
echo "[%{$fg_bold[yellow]%}$AWS_PROFILE%{$reset_color%}] "
else
echo ""
fi
}
directory_name() {
echo "%{$fg_bold[cyan]%}%1/%\/%{$reset_color%}"
}
prompt_symbol() {
echo "%{$fg_bold[green]%}→%{$reset_color%} "
}
export PROMPT=$'\n$(directory_name) $(git_dirty)$(need_push)$(aws_prompt)$(prompt_symbol)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment