4e101bed8661c342eade6d4ad094bdf3337b3b2e

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1558 from sbooob/master

Mercurial repository info in agnoster theme

Diff

 1diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
 2index c3107c06c04fb42b0ca27b0a81b15854819969c6..75e09577681863ca7fba4787bb29acd2559b55c6 100644
 3--- a/themes/agnoster.zsh-theme
 4+++ b/themes/agnoster.zsh-theme
 5@@ -83,6 +83,41 @@ prompt_git() {
 6   fi
 7 }
 8 
 9+prompt_hg() {
10+	local rev status
11+	if $(hg id >/dev/null 2>&1); then
12+		if $(hg prompt >/dev/null 2>&1); then
13+			if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
14+				# if files are not added
15+				prompt_segment red white
16+				st='±'
17+			elif [[ -n $(hg prompt "{status|modified}") ]]; then
18+				# if any modification
19+				prompt_segment yellow black
20+				st='±'
21+			else
22+				# if working copy is clean
23+				prompt_segment green black
24+			fi
25+			echo -n $(hg prompt "⭠ {rev}@{branch}") $st
26+		else
27+			st=""
28+			rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
29+			branch=$(hg id -b 2>/dev/null)
30+			if `hg st | grep -Eq "^\?"`; then
31+				prompt_segment red black
32+				st='±'
33+			elif `hg st | grep -Eq "^(M|A)"`; then
34+				prompt_segment yellow black
35+				st='±'
36+			else
37+				prompt_segment green black
38+			fi
39+			echo -n "⭠ $rev@$branch" $st
40+		fi
41+	fi
42+}
43+
44 # Dir: current working directory
45 prompt_dir() {
46   prompt_segment blue black '%~'
47@@ -109,6 +144,7 @@ build_prompt() {
48   prompt_context
49   prompt_dir
50   prompt_git
51+  prompt_hg
52   prompt_end
53 }
54