Last active
August 2, 2019 14:59
-
-
Save agirault/2503bafe81fb2a957a9ab88ef0aea951 to your computer and use it in GitHub Desktop.
To put in your bash_rc
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
# git status with a dirty flag | |
function __git_status_flag { | |
git_status="$(git status 2> /dev/null)" | |
clean_pattern="working tree clean" # For macOS. For Linux: "working directory clean" | |
remote_pattern="Your branch is (.*)" | |
diverge_pattern="Your branch and (.*) have diverged" | |
if [[ ! ${git_status} =~ ${clean_pattern} ]]; then | |
state="⚡ " | |
fi | |
if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
remote="🔺️ " | |
elif [[ ${BASH_REMATCH[1]} == "behind" ]]; then | |
remote="🔻 " | |
fi | |
fi | |
if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="⚠️ " | |
fi | |
echo "${state}${remote}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use:
PS1='\[\e[32m\]\u@\[\e[1m\]\h\[\e[22m\]:\[\e[1;34m\]\w\[\e[22;35m\]$(__git_ps1 " [\[\e[33m\]$(__git_status_flag)\[\e[35m\]%s]")\[\e[33m\] \$ \[\e[0m\]'