Skip to content

Instantly share code, notes, and snippets.

@colby
Created January 10, 2015 03:47
Show Gist options
  • Save colby/1b7e5b3e51dd5f548f24 to your computer and use it in GitHub Desktop.
Save colby/1b7e5b3e51dd5f548f24 to your computer and use it in GitHub Desktop.
# save last status
PROMPT_COMMAND='export last_status=$?'
PS1="\n\u@\H:\w\$(git_prompt)\n\$(last_status)\$ "
# only show status when non zero
function last_status {
if [ $last_status -gt 0 ]; then
echo $last_status
fi
}
function git_prompt {
# are we in a git repo?
if git rev-parse --is-inside-work-tree > /dev/null 2>&1
then
local branch=$(git symbolic-ref --short HEAD)
# check status only if we're not in a VM
if ! which virt-what > /dev/null 2>&1
then
local stat=$(git status 2>/dev/null)
local char=""
if [[ $(grep -c "Changes not staged \| Untracked files" $stat) -gt 0 ]]; then
char="$char?"
fi
if [[ $(grep -c "Changes to be committed" $stat) -gt 0 ]]; then
char="$char!"
fi
if [[ $(grep -c "nothing to commit" $stat) -gt 0 ]]; then
char=""
fi
if [[ $(grep -c "HEAD detached" $stat) -gt 0 ]]; then
char="$char%"
fi
fi
echo " $branch$char"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment