Skip to content
This repository
Newer
Older
100644 182 lines (162 sloc) 5.107 kb
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
1 # vim:ft=zsh ts=2 sw=2 sts=2
2 #
b207792f »
2012-09-25 Add link to gist
3 # agnoster's Theme - https://gist.github.com/3712874
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
4 # A Powerline-inspired theme for ZSH
5 #
6 # # README
7 #
8 # In order for this theme to render correctly, you will need a
78ffa71c »
2014-01-28 updated url to latest powerline-patched fonts
9 # [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
10 #
11 # In addition, I recommend the
12 # [Solarized theme](https://github.com/altercation/solarized/) and, if you're
13 # using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
14 # it has significantly better color fidelity.
15 #
16 # # Goals
17 #
18 # The aim of this theme is to only show you *relevant* information. Like most
19 # prompts, it will only show git information when in a git working directory.
20 # However, it goes a step further: everything from the current user and
21 # hostname to whether the last call exited with an error to whether background
22 # jobs are running in this shell will all be displayed automatically when
23 # appropriate.
24
bf415751 »
2012-09-17 Refactored theme
25 ### Segment drawing
26 # A few utility functions to make it easy and re-usable to draw segmented prompts
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
27
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
28 CURRENT_BG='NONE'
61e3951e »
2013-09-19 Revert "Replace no unicode glyph on hexa string"
29 SEGMENT_SEPARATOR=''
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
30
31 # Begin a segment
32 # Takes two arguments, background and foreground. Both can be omitted,
33 # rendering default background/foreground.
34 prompt_segment() {
35 local bg fg
36 [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
37 [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
38 if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
39 echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
bf415751 »
2012-09-17 Refactored theme
40 else
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
41 echo -n "%{$bg%}%{$fg%} "
bf415751 »
2012-09-17 Refactored theme
42 fi
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
43 CURRENT_BG=$1
44 [[ -n $3 ]] && echo -n $3
bf415751 »
2012-09-17 Refactored theme
45 }
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
46
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
47 # End the prompt, closing any open segments
48 prompt_end() {
bf415751 »
2012-09-17 Refactored theme
49 if [[ -n $CURRENT_BG ]]; then
50 echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
51 else
52 echo -n "%{%k%}"
53 fi
54 echo -n "%{%f%}"
55 CURRENT_BG=''
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
56 }
57
bf415751 »
2012-09-17 Refactored theme
58 ### Prompt components
59 # Each component will draw itself, and hide itself if no information needs to be shown
60
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
61 # Context: user@hostname (who am I and where am I)
62 prompt_context() {
bf415751 »
2012-09-17 Refactored theme
63 local user=`whoami`
64
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
65 if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
66 prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
bf415751 »
2012-09-17 Refactored theme
67 fi
68 }
69
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
70 # Git: branch/detached head, dirty status
71 prompt_git() {
53323abd »
2014-03-20 Added git mode support for merging, rebasing, and bisecting
72 local ref dirty mode repo_path
73 repo_path=$(git rev-parse --git-dir 2>/dev/null)
74
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
75 if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
76 dirty=$(parse_git_dirty)
3d762283 »
2012-11-27 fixed symbolic-ref git view of agnoster theme
77 ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
bf415751 »
2012-09-17 Refactored theme
78 if [[ -n $dirty ]]; then
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
79 prompt_segment yellow black
bf415751 »
2012-09-17 Refactored theme
80 else
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
81 prompt_segment green black
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
82 fi
ef8e3a67 »
2013-01-30 [agnoster] modifying theme to show dot for dirty files and plus for s…
83
53323abd »
2014-03-20 Added git mode support for merging, rebasing, and bisecting
84 if [[ -e "${repo_path}/BISECT_LOG" ]]; then
85 mode=" <B>"
86 elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
87 mode=" >M<"
88 elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
89 mode=" >R>"
90 fi
91
ef8e3a67 »
2013-01-30 [agnoster] modifying theme to show dot for dirty files and plus for s…
92 setopt promptsubst
93 autoload -Uz vcs_info
94
95 zstyle ':vcs_info:*' enable git
96 zstyle ':vcs_info:*' get-revision true
97 zstyle ':vcs_info:*' check-for-changes true
98 zstyle ':vcs_info:*' stagedstr '✚'
99 zstyle ':vcs_info:git:*' unstagedstr '●'
100 zstyle ':vcs_info:*' formats ' %u%c'
685ea4a3 »
2014-01-29 theme agnoster: remove trailing space
101 zstyle ':vcs_info:*' actionformats ' %u%c'
ef8e3a67 »
2013-01-30 [agnoster] modifying theme to show dot for dirty files and plus for s…
102 vcs_info
53323abd »
2014-03-20 Added git mode support for merging, rebasing, and bisecting
103 echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}"
bf415751 »
2012-09-17 Refactored theme
104 fi
105 }
106
8e9cf452 »
2013-01-19 ADDED: Mercurial repository info
107 prompt_hg() {
3930a632 »
2013-11-14 no tabs in a space-d file
108 local rev status
109 if $(hg id >/dev/null 2>&1); then
110 if $(hg prompt >/dev/null 2>&1); then
111 if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
112 # if files are not added
113 prompt_segment red white
114 st='±'
115 elif [[ -n $(hg prompt "{status|modified}") ]]; then
116 # if any modification
117 prompt_segment yellow black
118 st='±'
119 else
120 # if working copy is clean
121 prompt_segment green black
122 fi
123 echo -n $(hg prompt "☿ {rev}@{branch}") $st
124 else
125 st=""
126 rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
127 branch=$(hg id -b 2>/dev/null)
128 if `hg st | grep -Eq "^\?"`; then
129 prompt_segment red black
130 st='±'
131 elif `hg st | grep -Eq "^(M|A)"`; then
132 prompt_segment yellow black
133 st='±'
134 else
135 prompt_segment green black
136 fi
137 echo -n "☿ $rev@$branch" $st
138 fi
139 fi
8e9cf452 »
2013-01-19 ADDED: Mercurial repository info
140 }
141
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
142 # Dir: current working directory
143 prompt_dir() {
144 prompt_segment blue black '%~'
bf415751 »
2012-09-17 Refactored theme
145 }
146
ebfc9042 »
2013-06-25 add virtualenv prompt support for agnoster theme
147 # Virtualenv: current working virtualenv
148 prompt_virtualenv() {
149 local virtualenv_path="$VIRTUAL_ENV"
009b9061 »
2013-11-09 agnoster theme not showing virtualenv status
150 if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
ebfc9042 »
2013-06-25 add virtualenv prompt support for agnoster theme
151 prompt_segment blue black "(`basename $virtualenv_path`)"
152 fi
153 }
154
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
155 # Status:
156 # - was there an error
157 # - am I root
158 # - are there background jobs?
159 prompt_status() {
bf415751 »
2012-09-17 Refactored theme
160 local symbols
161 symbols=()
e4624c6a »
2012-12-21 Revert "agnoster theme shows error code instead of an "x""
162 [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
bf415751 »
2012-09-17 Refactored theme
163 [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
164 [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
165
166 [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
167 }
168
bf415751 »
2012-09-17 Refactored theme
169 ## Main prompt
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
170 build_prompt() {
bf415751 »
2012-09-17 Refactored theme
171 RETVAL=$?
172 prompt_status
ebfc9042 »
2013-06-25 add virtualenv prompt support for agnoster theme
173 prompt_virtualenv
7fc612bc »
2012-11-27 removed 'x' from prompt_context() function name
174 prompt_context
bf415751 »
2012-09-17 Refactored theme
175 prompt_dir
176 prompt_git
8e9cf452 »
2013-01-19 ADDED: Mercurial repository info
177 prompt_hg
6e85ff5b »
2012-09-25 Updated documentation for agnoster theme
178 prompt_end
bf415751 »
2012-09-17 Refactored theme
179 }
b11e2891 »
2012-09-13 Add agnoster.zsh-theme
180
7fc612bc »
2012-11-27 removed 'x' from prompt_context() function name
181 PROMPT='%{%f%b%k%}$(build_prompt) '
Something went wrong with that request. Please try again.