diff --git a/README.md b/README.md index 429d322..7f9263b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/prompt.sh b/prompt.sh index 78e9615..d4cfca5 100644 --- a/prompt.sh +++ b/prompt.sh @@ -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 @@ -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}, " @@ -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}, " @@ -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