Simplified Git Status for use in zsh prompts with fonts including FontAwesome.
Last active
February 11, 2018 21:47
-
-
Save moqmar/656453680f72d324cc718285c108b6b2 to your computer and use it in GitHub Desktop.
Simplified Git Status for use in zsh prompts with fonts including FontAwesome.
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
function zsh-git-status(){ if ! git rev-parse --is-inside-work-tree>/dev/null 2>&1;then return 1;fi;git rev-parse @{u}>/dev/null 2>&1;HAS_REMOTE=$?;ZSH_GIT_REMOTE_STATUS="";if [ $HAS_REMOTE -eq 0 ];then LOCAL=$(git rev-parse @ 2>/dev/null);REMOTE=$(git rev-parse @{u} 2>/dev/null);BASE=$(git merge-base @ @{u} 2>/dev/null);if [ $LOCAL = $REMOTE ];then ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[green]%} ";elif [ $LOCAL = $BASE ];then ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[yellow]%} ";elif [ $REMOTE = $BASE ];then ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[yellow]%} ";else ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[red]%} ";fi;fi;if [ $(git status --porcelain 2>/dev/null|wc -l) -gt 0 ];then branch=`git symbolic-ref --short -q HEAD 2>/dev/null`;[ -z "$branch" ]&&branch=`git rev-parse --short HEAD 2>/dev/null`;echo -n " $ZSH_GIT_REMOTE_STATUS%{$fg_bold[red]%}$branch";else branch=`git symbolic-ref --short -q HEAD 2>/dev/null`;[ -z "$branch" ]&&branch=`git rev-parse --short HEAD 2>/dev/null`;echo -n " $ZSH_GIT_REMOTE_STATUS%{$fg_bold[green]%}$branch";fi;} |
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
function zsh-git-status() { | |
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then | |
return 1 | |
fi | |
git rev-parse @{u} >/dev/null 2>&1 | |
HAS_REMOTE=$? | |
ZSH_GIT_REMOTE_STATUS="" | |
if [ $HAS_REMOTE -eq 0 ]; then | |
# http://stackoverflow.com/a/3278427/2081430 | |
LOCAL=$(git rev-parse @ 2>/dev/null) | |
REMOTE=$(git rev-parse @{u} 2>/dev/null) | |
BASE=$(git merge-base @ @{u} 2>/dev/null) | |
if [ $LOCAL = $REMOTE ]; then | |
ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[green]%} " | |
elif [ $LOCAL = $BASE ]; then | |
ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[yellow]%} " | |
elif [ $REMOTE = $BASE ]; then | |
ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[yellow]%} " | |
else | |
ZSH_GIT_REMOTE_STATUS="%{$fg_no_bold[red]%} " | |
fi | |
fi | |
if [ $(git status --porcelain 2>/dev/null | wc -l) -gt 0 ]; then # Uncommitted changes or untracked files | |
branch=`git symbolic-ref --short -q HEAD 2>/dev/null` | |
[ -z "$branch" ] && branch=`git rev-parse --short HEAD 2>/dev/null` | |
echo -n " $ZSH_GIT_REMOTE_STATUS%{$fg_bold[red]%}$branch" | |
else | |
branch=`git symbolic-ref --short -q HEAD 2>/dev/null` | |
[ -z "$branch" ] && branch=`git rev-parse --short HEAD 2>/dev/null` | |
echo -n " $ZSH_GIT_REMOTE_STATUS%{$fg_bold[green]%}$branch" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment