Last active
December 25, 2015 17:49
-
-
Save tboyce12/7016126 to your computer and use it in GitHub Desktop.
Shell prompt w/user, directory, git branch with dirty status
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
| 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\] $ " |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

For alternative colors, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors