Skip to content

Instantly share code, notes, and snippets.

@palesz
Created May 15, 2020 14:46
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 palesz/76d81ad55005fbd112cb79e6f73e29ec to your computer and use it in GitHub Desktop.
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
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