Browse code

Added my prompt theme, with a tweak to the core oh-my-zsh to support it. My git_prompt_info function not only reports the branch and dirty status, but also whether or not the branch is ahead or behind of the remote, or both. It also switches the prompt colour from green to red if the previous command exited with a non-zero value (i.e. failed).

James Adam authored on 19/10/2009 at 22:24:21
Showing 2 changed files
... ...
@@ -4,6 +4,7 @@ case "$TERM" in
4 4
       print -Pn "\e]0;%n@%m: $1\a"  # xterm
5 5
     }
6 6
     precmd () {
7
+      oh_my_zsh_theme_precmd
7 8
       print -Pn "\e]0;%n@%m: %~\a"  # xterm
8 9
     }
9 10
     ;;
... ...
@@ -14,6 +15,7 @@ case "$TERM" in
14 14
       print -Pn "\e]0;%n@%m: $1\a"  # xterm
15 15
     }
16 16
     precmd () {
17
+      oh_my_zsh_theme_precmd
17 18
       echo -ne "\ekzsh\e\\"
18 19
       print -Pn "\e]0;%n@%m: %~\a"  # xterm
19 20
     }
20 21
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+git_prompt_info() {
1
+  branch=$(git symbolic-ref HEAD 2> /dev/null) || return
2
+  git_status="$(git status 2> /dev/null)"
3
+  state=""
4
+  case $git_status in
5
+    *Changed\ but\ not\ updated*)
6
+      state="%{$fg[red]%}⚡"
7
+    ;;;
8
+    *Untracked\ files*)
9
+      state="%{$fg[red]%}⚡"
10
+    ;;;
11
+  esac
12
+  
13
+  remote=""
14
+  case $git_status in
15
+    *Your\ branch\ is\ ahead*)
16
+      remote="%{$fg[yellow]%}↑"
17
+    ;;;
18
+    
19
+    *Your\ branch\ is\ behind*)
20
+      remote="%{$fg[yellow]%}↓"
21
+    ;;;
22
+    
23
+    "Your branch and")
24
+      remote="%{$fg[yellow]%}"
25
+    ;;;
26
+  esac
27
+  echo " %{$fg[yellow]%}(${branch#refs/heads/})${remote}${state}"
28
+}
29
+
30
+function oh_my_zsh_theme_precmd() {
31
+  local previous_return_value=$?;
32
+  prompt="%{$fg[light_gray]%}%c%{$fg[yellow]%}$(git_prompt_info)%{$fg[white]%}"
33
+  if test $previous_return_value -eq 0
34
+  then
35
+    export PROMPT="%{$fg[green]%}➜  %{$fg[white]%}${prompt}%{$fg[green]%} $%{$fg[white]%} "
36
+  else
37
+    export PROMPT="%{$fg[red]%}➜  %{$fg[white]%}${prompt}%{$fg[red]%} $%{$fg[white]%} "
38
+  fi
39
+}
0 40
\ No newline at end of file