14a1ce80bbf7362ab2856cdd050714f02649fe3f
Author James Adam <james@lazyatom.com> Committer Robby Russell <robby@planetargon.com> Date 2009-11-08 23:14 UTC
Message 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).
Diff 1 diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
2 index fef9787486b1d2f5d06ae49958dc0dad73235ff0..ec828c287f7db9d53af4eff662284de1f69cbc36 100644
3 --- a/lib/termsupport.zsh
4 +++ b/lib/termsupport.zsh
5 @@ -4,6 +4,7 @@ case "$TERM" in
6 print -Pn "\e]0;%n@%m: $1\a" # xterm
7 }
8 precmd () {
9 + oh_my_zsh_theme_precmd
10 print -Pn "\e]0;%n@%m: %~\a" # xterm
11 }
12 ;;
13 @@ -14,6 +15,7 @@ case "$TERM" in
14 print -Pn "\e]0;%n@%m: $1\a" # xterm
15 }
16 precmd () {
17 + oh_my_zsh_theme_precmd
18 echo -ne "\ekzsh\e\\"
19 print -Pn "\e]0;%n@%m: %~\a" # xterm
20 }
21 diff --git a/themes/lazyatom.zsh-theme b/themes/lazyatom.zsh-theme
22 new file mode 100644
23 index 0000000000000000000000000000000000000000..6263bc2b74bccb69909bd7bf1e1864e0c3992c75
24 --- /dev/null
25 +++ b/themes/lazyatom.zsh-theme
26 @@ -0,0 +1,40 @@
27 +git_prompt_info() {
28 + branch=$(git symbolic-ref HEAD 2> /dev/null) || return
29 + git_status="$(git status 2> /dev/null)"
30 + state=""
31 + case $git_status in
32 + *Changed\ but\ not\ updated*)
33 + state="%{$fg[red]%}⚡"
34 + ;;;
35 + *Untracked\ files*)
36 + state="%{$fg[red]%}⚡"
37 + ;;;
38 + esac
39 +
40 + remote=""
41 + case $git_status in
42 + *Your\ branch\ is\ ahead*)
43 + remote="%{$fg[yellow]%}↑"
44 + ;;;
45 +
46 + *Your\ branch\ is\ behind*)
47 + remote="%{$fg[yellow]%}↓"
48 + ;;;
49 +
50 + "Your branch and")
51 + remote="%{$fg[yellow]%}"
52 + ;;;
53 + esac
54 + echo " %{$fg[yellow]%}(${branch#refs/heads/})${remote}${state}"
55 +}
56 +
57 +function oh_my_zsh_theme_precmd() {
58 + local previous_return_value=$?;
59 + prompt="%{$fg[light_gray]%}%c%{$fg[yellow]%}$(git_prompt_info)%{$fg[white]%}"
60 + if test $previous_return_value -eq 0
61 + then
62 + export PROMPT="%{$fg[green]%}➜ %{$fg[white]%}${prompt}%{$fg[green]%} $%{$fg[white]%} "
63 + else
64 + export PROMPT="%{$fg[red]%}➜ %{$fg[white]%}${prompt}%{$fg[red]%} $%{$fg[white]%} "
65 + fi
66 +}