From fd7a0ca9592864b863524502a54151ae7b35222b Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Fri, 11 May 2012 09:10:36 +0100 Subject: [PATCH 1/5] Fixing AH's Twitter URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 9c42996c22e5b668f5d22d107d0480e988b24e8c Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Fri, 11 May 2012 09:14:14 +0100 Subject: [PATCH 2/5] Adding a count to show how far ahead of your branch you are. Essentially, the number of commits you've made since your last push. --- prompt.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prompt.sh b/prompt.sh index 78e9615..3a841dd 100644 --- a/prompt.sh +++ b/prompt.sh @@ -160,6 +160,10 @@ function repo_status { # status of current repo if in_git_repo; then 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 From 2cc49e4aa6134d97b549cd64d529b8949eab03ef Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Fri, 11 May 2012 09:19:15 +0100 Subject: [PATCH 3/5] Adjusting repo status checks to allow for 'staged' count. --- prompt.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/prompt.sh b/prompt.sh index 3a841dd..c352026 100644 --- a/prompt.sh +++ b/prompt.sh @@ -159,7 +159,7 @@ 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" @@ -176,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}, " @@ -191,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}, " @@ -200,7 +200,7 @@ 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}, " @@ -218,7 +218,7 @@ function repo_status { fi # untracked file count - local untracked="$(echo "$lstatus" | grep -c '^[gm]?')" + local untracked="$(echo "$lstatus" | grep -c '^g *?')" if [[ "$untracked" -gt 0 ]]; then if [[ "$changes" != "" ]]; then changes="${changes}, " @@ -226,6 +226,15 @@ function repo_status { changes="${changes}${untracked} untracked" fi + # 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}${staged} staged" + fi + if [[ "$changes" != "" ]]; then changes=" (${changes})" fi From d247bdff64cc1e4ead25b0f0516a25a01c59efb7 Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Fri, 11 May 2012 09:20:12 +0100 Subject: [PATCH 4/5] Removing redundant missing file check --- prompt.sh | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/prompt.sh b/prompt.sh index c352026..53200f7 100644 --- a/prompt.sh +++ b/prompt.sh @@ -207,16 +207,7 @@ function repo_status { fi changes="${changes}${removed} renamed" fi - - # missing file count - local missing="$(echo "$lstatus" | grep -c '^m!')" - if [[ "$missing" -gt 0 ]]; then - if [[ "$changes" != "" ]]; then - changes="${changes}, " - fi - changes="${changes}${missing} missing" - fi - + # untracked file count local untracked="$(echo "$lstatus" | grep -c '^g *?')" if [[ "$untracked" -gt 0 ]]; then From 4e6b39d3616237314b5279b1f7c27bf2c3ac36a0 Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Fri, 18 May 2012 16:12:29 -0400 Subject: [PATCH 5/5] Fixing buggy regex on ahead count --- prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt.sh b/prompt.sh index 53200f7..d4cfca5 100644 --- a/prompt.sh +++ b/prompt.sh @@ -160,7 +160,7 @@ function repo_status { # status of current repo if in_git_repo; then local lstatus="`get_repo_status | sed 's/^/g/'`" - local ahead="`git status | grep 'Your branch is ahead' | sed -Ee 's/^.*([0-9]+) commit.*$/\1/'`" + 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