-
-
Save odracci/2072958 to your computer and use it in GitHub Desktop.
My version with tweaks and inspiration from holman/dotfiles
This file contains 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
# http://henrik.nyh.se/2008/12/git-dirty-prompt | |
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ | |
# username@Machine ~/dev/dir[master]$ # clean working directory | |
# username@Machine ~/dev/dir[master*]$ # dirty working directory | |
function parse_git_unpushed { | |
local unpushed=`/usr/bin/git cherry -v origin/$(get_git_branch) 2> /dev/null` | |
[[ "$unpushed" != "" ]] && echo "$(tput setaf 1) ++> $(tput sgr0)" | |
} | |
function parse_git_dirty { | |
git diff --quiet HEAD &>/dev/null | |
[[ $? == 1 ]] && echo " $(tput bold)$(tput setaf 3)*$(tput sgr0)" | |
[[ $(git status --porcelain|grep '^??' 2> /dev/null | tail -n1) != "" ]] && echo -n " $(tput bold)$(tput setaf 5)+$(tput sgr0)" | |
} | |
function get_git_branch { | |
echo $(__git_ps1 "%s") | |
} | |
function parse_git_branch { | |
local branch=$(get_git_branch) | |
[[ $branch ]] && echo "[$(tput setaf 6)$branch$(tput sgr0)$(parse_git_dirty)]$(parse_git_unpushed)" | |
} | |
if [ $(id -u) -eq 0 ]; | |
then # you are root, set red colour prompt | |
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]" | |
else # normal | |
PS1='\[$(tput bold ; tput setaf 6)\][\t]\[$(tput setaf 2)\] \u@\h \[$(parse_git_branch)\]\n \[$(tput setaf 4)\]\w \[$(tput sgr0)\]\$ ' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment