]> git.rmz.io Git - dotfiles.git/blob - zsh/themes/agnoster.zsh-theme
update zshrc
[dotfiles.git] / zsh / themes / agnoster.zsh-theme
1 # vim:ft=zsh ts=2 sw=2 sts=2
2 #
3 # agnoster's Theme - https://gist.github.com/3712874
4 # A Powerline-inspired theme for ZSH
5 #
6 # # README
7 #
8 # In order for this theme to render correctly, you will need a
9 # [Powerline-patched font](https://gist.github.com/1595572).
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
25 ### Segment drawing
26 # A few utility functions to make it easy and re-usable to draw segmented prompts
27
28 CURRENT_BG='NONE'
29 SEGMENT_SEPARATOR='⮀'
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%} "
40 else
41 echo -n "%{$bg%}%{$fg%} "
42 fi
43 CURRENT_BG=$1
44 [[ -n $3 ]] && echo -n $3
45 }
46
47 # End the prompt, closing any open segments
48 prompt_end() {
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=''
56 }
57
58 ### Prompt components
59 # Each component will draw itself, and hide itself if no information needs to be shown
60
61 # Context: user@hostname (who am I and where am I)
62 prompt_context() {
63 local user=`whoami`
64
65 if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
66 prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
67 fi
68 }
69
70 # Git: branch/detached head, dirty status
71 prompt_git() {
72 local ref dirty
73 if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
74 ZSH_THEME_GIT_PROMPT_DIRTY='±'
75 dirty=$(parse_git_dirty)
76 ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
77 if [[ -n $dirty ]]; then
78 prompt_segment yellow black
79 else
80 prompt_segment green black
81 fi
82 echo -n "${ref/refs\/heads\//⭠ }$dirty"
83 fi
84 }
85
86 # Dir: current working directory
87 prompt_dir() {
88 prompt_segment blue black '%~'
89 }
90
91 # Status:
92 # - was there an error
93 # - am I root
94 # - are there background jobs?
95 prompt_status() {
96 local symbols
97 symbols=()
98 [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$RETVAL"
99 [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
100 [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
101
102 [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
103 }
104
105 ## Main prompt
106 build_prompt() {
107 RETVAL=$?
108 prompt_status
109 prompt_context
110 prompt_dir
111 prompt_git
112 prompt_end
113 }
114
115 PROMPT='%{%f%b%k%}$(build_prompt) '