c1b798aff39942b2f23a0a5f2ef206ebc8ce4970

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

agnoster: fix bzr prompt with breezy installed (#8646)

* Change indentation to 2 spaces in prompt_bzr function
* Check if in a bzr repository and optimize bzr calls in prompt_bzr

Diff

 1diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
 2index 518a14a37562d40768dc21c130ca17ca000e4e4f..8c700d06adb639b60d5adaef30af0857053b095f 100644
 3--- a/themes/agnoster.zsh-theme
 4+++ b/themes/agnoster.zsh-theme
 5@@ -140,24 +140,30 @@ prompt_git() {
 6 }
 7 
 8 prompt_bzr() {
 9-    (( $+commands[bzr] )) || return
10-    if (bzr status >/dev/null 2>&1); then
11-        status_mod=`bzr status | head -n1 | grep "modified" | wc -m`
12-        status_all=`bzr status | head -n1 | wc -m`
13-        revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
14-        if [[ $status_mod -gt 0 ]] ; then
15-            prompt_segment yellow black
16-            echo -n "bzr@"$revision "✚ "
17-        else
18-            if [[ $status_all -gt 0 ]] ; then
19-                prompt_segment yellow black
20-                echo -n "bzr@"$revision
21-            else
22-                prompt_segment green black
23-                echo -n "bzr@"$revision
24-            fi
25-        fi
26+  (( $+commands[bzr] )) || return
27+
28+  # Test if bzr repository in directory hierarchy
29+  local dir="$PWD"
30+  while [[ ! -d "$dir/.bzr" ]]; do
31+    [[ "$dir" = "/" ]] && return
32+    dir="${dir:h}"
33+  done
34+
35+  local bzr_status status_mod status_all revision
36+  if bzr_status=$(bzr status 2>&1); then
37+    status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
38+    status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
39+    revision=$(bzr log -r-1 --log-format line | cut -d: -f1)
40+    if [[ $status_mod -gt 0 ]] ; then
41+      prompt_segment yellow black "bzr@$revision ✚"
42+    else
43+      if [[ $status_all -gt 0 ]] ; then
44+        prompt_segment yellow black "bzr@$revision"
45+      else
46+        prompt_segment green black "bzr@$revision"
47+      fi
48     fi
49+  fi
50 }
51 
52 prompt_hg() {