Created
May 15, 2020 14:46
-
-
Save palesz/76d81ad55005fbd112cb79e6f73e29ec to your computer and use it in GitHub Desktop.
Change the zsh (or other shell) PROMPT to contain basic git status information
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
function git_status() { | |
if git status >/dev/null 2>/dev/null; then | |
status_str=`git status -s 2>/dev/null | cut -f1 -d' ' | uniq -c | awk '{ print $2 " " $1 }' | paste -s -d' '` | |
branch=`git branch --show-current` | |
commit_hash=`git log -1 --format=%h` | |
echo "[git: $commit_hash $branch $status_str]" | |
fi | |
} | |
# important (!) | |
setopt PROMPT_SUBST | |
export __GIT_STATUS='$(git_status)' | |
export PROMPT="... $__GIT_STATUS ..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment