Last active
April 23, 2017 13:08
-
-
Save nishina555/4639d315799aae855d128e9cfe541367 to your computer and use it in GitHub Desktop.
Showing the git branch name with the color
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
# prompt | |
if [ $UID -eq 0 ];then | |
PROMPT="%F{red}%n:%f%F{green}%d%f [%m] %% | |
" | |
PROMPT2="%F{red}%n:%f%F{green}%_%f [%m] %% | |
" | |
else | |
# mac | |
PROMPT="%F{cyan}%n:%f%F{green}%d%f [%m] %% | |
" | |
PROMPT2="%F{cyan}%n:%f%F{green}%_%f [%m] %% | |
" | |
fi | |
# funciton for showing git branch status | |
function rprompt-git-current-branch { | |
local branch_name st branch_status | |
if [ ! -e ".git" ]; then | |
# the case where the directory is not managed by git | |
return | |
fi | |
branch_name=`git rev-parse --abbrev-ref HEAD 2> /dev/null` | |
st=`git status 2> /dev/null` | |
if [[ -n `echo "$st" | grep "^nothing to"` ]]; then | |
# clean | |
branch_status="%F{green}" | |
elif [[ -n `echo "$st" | grep "^Untracked files"` ]]; then | |
# untracked | |
branch_status="%F{red}?" | |
elif [[ -n `echo "$st" | grep "^Changes not staged for commit"` ]]; then | |
# modified | |
branch_status="%F{red}+" | |
elif [[ -n `echo "$st" | grep "^Changes to be committed"` ]]; then | |
# staged | |
branch_status="%F{yellow}!" | |
elif [[ -n `echo "$st" | grep "^rebase in progress"` ]]; then | |
# the case where there is some actions such as conflict | |
echo "%F{red}!(no branch)" | |
return | |
else | |
# other case | |
branch_status="%F{blue}" | |
fi | |
echo "${branch_status}[$branch_name]" | |
} | |
setopt prompt_subst | |
RPROMPT='`rprompt-git-current-branch`' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment