1 # vim:ft=zsh ts=2 sw=2 sts=2
 
   3 # agnoster's Theme - https://gist.github.com/3712874
 
   4 # A Powerline-inspired theme for ZSH
 
   8 # In order for this theme to render correctly, you will need a
 
   9 # [Powerline-patched font](https://gist.github.com/1595572).
 
  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.
 
  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
 
  26 # A few utility functions to make it easy and re-usable to draw segmented prompts
 
  32 # Takes two arguments, background and foreground. Both can be omitted,
 
  33 # rendering default background/foreground.
 
  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%} "
 
  41     echo -n "%{$bg%}%{$fg%} "
 
  44   [[ -n $3 ]] && echo -n $3
 
  47 # End the prompt, closing any open segments
 
  49   if [[ -n $CURRENT_BG ]]; then
 
  50     echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
 
  59 # Each component will draw itself, and hide itself if no information needs to be shown
 
  61 # Context: user@hostname (who am I and where am I)
 
  65   if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
 
  66     prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
 
  70 # Git: branch/detached head, dirty status
 
  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
 
  80       prompt_segment green black
 
  82     echo -n "${ref/refs\/heads\//⭠ }$dirty"
 
  86 # Dir: current working directory
 
  88   prompt_segment blue black '%~'
 
  92 # - was there an error
 
  94 # - are there background jobs?
 
  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}%}⚙"
 
 102   [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
 
 115 PROMPT='%{%f%b%k%}$(build_prompt) '