Skip to content

Different coloured background according to git status #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ non-retina screens. I'd rather stick with existing unicode symbols in the fonts.
Powerline.
* [emacs powerline](https://github.com./milkypostman/powerline): Powerline for
Emacs


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vergissberlin/bash-powerline/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

15 changes: 12 additions & 3 deletions bash-powerline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ __powerline() {

# branch is modified?
[ -n "$(git status --porcelain)" ] && marks+=" $GIT_BRANCH_CHANGED_SYMBOL"

local git_status="`git status -unormal --ignore-submodules 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local colour=$BG_GREEN
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local colour=$BG_RED
else
local colour=$BG_YELLOW
fi
fi
# how many commits local branch is ahead/behind of remote?
local stat="$(git status --porcelain --branch | grep '^##' | grep -o '\[.\+\]$')"
local aheadN="$(echo $stat | grep -o 'ahead \d\+' | grep -o '\d\+')"
Expand All @@ -85,7 +94,7 @@ __powerline() {
[ -n "$behindN" ] && marks+=" $GIT_NEED_PULL_SYMBOL$behindN"

# print the git branch segment without a trailing newline
printf " $GIT_BRANCH_SYMBOL$branch$marks "
printf " $GIT_BRANCH_SYMBOL$branch$marks$RESET "
}

ps1() {
Expand All @@ -98,7 +107,7 @@ __powerline() {
fi

PS1="$BG_BASE1$FG_BASE3 \w $RESET"
PS1+="$BG_BLUE$FG_BASE3$(__git_info)$RESET"
PS1+="$(__git_info)"
PS1+="$BG_EXIT$FG_BASE3 $PS_SYMBOL $RESET "
}

Expand Down