Created
August 10, 2021 11:11
-
-
Save paulswail/7857200a9e3ec8b122f3bba20aec1c02 to your computer and use it in GitHub Desktop.
ZSH prompt with Git and AWS profile status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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