Skip to content

Because, apparently... #1

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 5 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ As well as the usual stuff you might like in your prompt, it displays which part

This is entirely based on Steve Losh's excellent work, both his "[extravagant zsh prompt](http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/)" (note his zsh prompt is more sophisticated than this one detailed here) - and [hg-prompt](http://stevelosh.com/projects/hg-prompt/) as well.

The infinitely talented [Andrew Hayward](https://github.com/andrewhayward)([@arhayward](twitter.com/arhayward)) wrote most of the code, I just fixed a few bugs (doubtlessly introducing a few of my own) and made it work in zsh as well as bash (I've tried to use as much shell-agnostic code as possible - although there's probably quite a bit of it that is non POSIX-compliant - would be nice to see it forked and working in other shells as well!)
The infinitely talented [Andrew Hayward](https://github.com/andrewhayward)([@arhayward](https://twitter.com/arhayward)) wrote most of the code, I just fixed a few bugs (doubtlessly introducing a few of my own) and made it work in zsh as well as bash (I've tried to use as much shell-agnostic code as possible - although there's probably quite a bit of it that is non POSIX-compliant - would be nice to see it forked and working in other shells as well!)

Oh, and - like 90% of projects on teh internets - I also received a bit of help from [Matthew Somerville](http://www.dracos.co.uk/)([@dracos](https://twitter.com/dracos)) as well.

Expand Down
34 changes: 19 additions & 15 deletions prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ function repo_status {

# status of current repo
if in_git_repo; then
local lstatus="`get_repo_status | sed 's/^ */g/'`"
local lstatus="`get_repo_status | sed 's/^/g/'`"
local ahead="`git status | grep 'Your branch is ahead' | sed -Ee 's/^.* ([0-9]+) commit.*$/\1/'`"
if [[ "$ahead" != '' ]]; then
local branch="${branch}${msrp_preposition_color} + $ahead"
fi
else
local lstatus=''
fi
Expand All @@ -172,13 +176,13 @@ function repo_status {
local changes=""

# modified file count
local modified="$(echo "$lstatus" | grep -c '^[gm]M')"
local modified="$(echo "$lstatus" | grep -c '^g *M')"
if [[ "$modified" -gt 0 ]]; then
changes="$modified changed"
fi

# added file count
local added="$(echo "$lstatus" | grep -c '^[gm]A')"
local added="$(echo "$lstatus" | grep -c '^g *A')"
if [[ "$added" -gt 0 ]]; then
if [[ "$changes" != "" ]]; then
changes="${changes}, "
Expand All @@ -187,7 +191,7 @@ function repo_status {
fi

# removed file count
local removed="$(echo "$lstatus" | grep -c '^(mR|gD)')"
local removed="$(echo "$lstatus" | grep -c '^g *D')"
if [[ "$removed" -gt 0 ]]; then
if [[ "$changes" != "" ]]; then
changes="${changes}, "
Expand All @@ -196,32 +200,32 @@ function repo_status {
fi

# renamed file count
local renamed="$(echo "$lstatus" | grep -c '^gR')"
local renamed="$(echo "$lstatus" | grep -c '^g *R')"
if [[ "$renamed" -gt 0 ]]; then
if [[ "$changes" != "" ]]; then
changes="${changes}, "
fi
changes="${changes}${removed} renamed"
fi

# missing file count
local missing="$(echo "$lstatus" | grep -c '^m!')"
if [[ "$missing" -gt 0 ]]; then
# untracked file count
local untracked="$(echo "$lstatus" | grep -c '^g *?')"
if [[ "$untracked" -gt 0 ]]; then
if [[ "$changes" != "" ]]; then
changes="${changes}, "
fi
changes="${changes}${missing} missing"
changes="${changes}${untracked} untracked"
fi

# untracked file count
local untracked="$(echo "$lstatus" | grep -c '^[gm]?')"
if [[ "$untracked" -gt 0 ]]; then
# staged file count
local staged="$(echo "$lstatus" | grep -c '^g[A-Z]')"
if [[ "$staged" -gt 0 ]]; then
if [[ "$changes" != "" ]]; then
changes="${changes}, "
fi
changes="${changes}${untracked} untracked"
changes="${changes}${staged} staged"
fi

if [[ "$changes" != "" ]]; then
changes=" (${changes})"
fi
Expand Down