Created
March 14, 2014 19:07
-
-
Save junosuarez/9554589 to your computer and use it in GitHub Desktop.
git status prompt
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
function parse_git_branch { | |
local W="\033[1;37m" | |
local ref=$(git symbolic-ref HEAD 2> /dev/null) | |
if [[ -z $ref ]]; then | |
return | |
fi | |
echo -e $W"/"${ref#refs/heads/}" " | |
} | |
function parse_git_status { | |
local st=$(git status 2> /dev/null) | |
if [[ -z $st ]]; then | |
return | |
fi | |
local staged=false; | |
if [[ ! -z $(git status --porcelain | grep "^M") ]]; then | |
local staged=true | |
fi | |
local modified=false; | |
if [[ ! -z $(git status --porcelain | grep "^ M") ]]; then | |
local modified=true | |
fi | |
local untracked=false; | |
if [[ ! -z $(git status --porcelain | grep "^??") ]]; then | |
local untracked=true | |
fi | |
#echo . | |
#echo "staged "$staged | |
#echo "modified "$modified | |
#echo "untracked "$untracked | |
#echo . | |
local Y="\033[1;33m" | |
local G="\033[1;32m" | |
local R="\033[1;31m" | |
if $staged || $modified || $untracked; then | |
echo -e $Y"*" | |
elif [[ ! -z $(git status | tail -n 1 | grep "working directory clean") ]]; then | |
echo -e $G"clean" | |
else | |
echo -e $R"!" | |
fi | |
} | |
function get_local_dir { | |
#echo $(expr `pwd` : '.*/\(.*\)') | |
pwd | |
} | |
GREY="\[\033[0;37m\]" | |
RED="\[\033[1;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
PLAIN="\[\033[0m\]" | |
PS1=$GREY"\njden \$(get_local_dir) \$(parse_git_branch)$PLAIN\$(parse_git_status)"$GREY"\n> $PLAIN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment