Skip to content

Instantly share code, notes, and snippets.

@tboyce12
Last active December 25, 2015 17:49
Show Gist options
  • Save tboyce12/7016126 to your computer and use it in GitHub Desktop.
Save tboyce12/7016126 to your computer and use it in GitHub Desktop.
Shell prompt w/user, directory, git branch with dirty status
tb_is_git_dirty() {
git_status="$(git status 2> /dev/null)"
if [[ ${git_status} =~ "nothing to commit" ]]; then
return 0
else
return 1
fi
}
__tb_git_status() {
git_status="$(git status 2> /dev/null)"
git_branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [ -n "${git_status}" -a -n "${git_branch}" ]; then
if __tb_is_git_dirty; then
echo " (${git_branch})"
else
echo " (${git_branch}*)"
fi
fi
}
tb_git_status_color() {
if tb_is_git_dirty; then echo -e "\x1B[32m"; else echo -e "\x1B[1;32m"; fi
}
export PS1="\[\e[1;30m\]\u \[\e[0;35m\]\W\[\$(tb_git_status_color)\]\$(tb_git_status)\[\e[m\] $ "
@tboyce12
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment