bf4157514f8880ac04ba328f7f1b74c34f1b39d7

Author
Isaac Wolkerstorfer <i@agnoster.net>
Committer
Isaac Wolkerstorfer <i@agnoster.net>
Date

Message

Refactored theme

Diff

This diff is truncated to protect this page.

  1diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
  2index 15848979eedb7f2a947c0e322ae9ac68b208eb64..9cfcff3d0e07fce6a23c7344e11e96b706d88eab 100644
  3--- a/themes/agnoster.zsh-theme
  4+++ b/themes/agnoster.zsh-theme
  5@@ -1,28 +1,86 @@
  6-# Theme by [agnoster](https://github.com/agnoster)
  7-# See https://gist.github.com/3712874
  8+### Segment drawing
  9+# A few utility functions to make it easy and re-usable to draw segmented prompts
 10 
 11-ZSH_THEME_GIT_PROMPT_DIRTY='±'
 12+CURRENT_BG=''
 13+SEGMENT_SEPARATOR='⮀'
 14+function segment_start() {
 15+  local bg=$1
 16+  local fg=$2
 17+  if [[ -n $CURRENT_BG && $bg != $CURRENT_BG ]]; then
 18+    echo -n " %{%K{$bg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
 19+  else
 20+    echo -n "%{%K{$bg}%}"
 21+  fi
 22+  [[ -n $fg ]] && fg="%F{$fg}" || fg="%f"
 23+  echo -n "%{$fg%} "
 24+  CURRENT_BG=$bg
 25+}
 26 
 27-function _git_prompt_info() {
 28-  ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
 29-  echo "${ref/refs\/heads\//⭠ }$(parse_git_dirty)"
 30+function segment_stop() {
 31+  if [[ -n $CURRENT_BG ]]; then
 32+    echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
 33+  else
 34+    echo -n "%{%k%}"
 35+  fi
 36+  echo -n "%{%f%}"
 37+  CURRENT_BG=''
 38 }
 39 
 40-function _git_info() {
 41+### Prompt components
 42+# Each component will draw itself, and hide itself if no information needs to be shown
 43+
 44+function prompt_context() {
 45+  local user=`whoami`
 46+
 47+  if [[ ("$user" != "$DEFAULT_USER") || (-n "$SSH_CLIENT") ]]; then
 48+    segment_start black
 49+    #echo -n "%{%F{yellow}%}$user%{%F{gray}%}@%{%F{green}%}%m%{%f%}"
 50+    echo -n "%(!.%{%F{yellow}%}.)$user@%m"
 51+  fi
 52+}
 53+
 54+function prompt_git() {
 55   if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
 56-    local BG_COLOR=green
 57-    if [[ -n $(parse_git_dirty) ]]; then
 58-      BG_COLOR=yellow
 59+    ZSH_THEME_GIT_PROMPT_DIRTY='±'
 60+    local dirty=$(parse_git_dirty)
 61+    local ref
 62+    ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
 63+    if [[ -n $dirty ]]; then
 64+      segment_start yellow black
 65+    else
 66+      segment_start green black
 67     fi
 68-    echo "%{%K{$BG_COLOR}%}⮀%{%F{black}%} $(_git_prompt_info) %{%F{$BG_COLOR}%K{blue}%}⮀"
 69-  else
 70-    echo "%{%K{blue}%}⮀"
 71+    echo -n "${ref/refs\/heads\//⭠ }$dirty"
 72+  fi
 73+}
 74+
 75+function prompt_dir() {
 76+  segment_start blue white
 77+  echo -n '%~'
 78+}
 79+
 80+function prompt_status() {
 81+  local symbols
 82+  symbols=()
 83+  [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
 84+  [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
 85+  jobs=$(jobs -l | wc -l)
 86+  [[ $jobs -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
 87+  if [[ -n "$symbols" ]]; then
 88+    segment_start black white
 89+    echo -n "${symbols}"
 90   fi
 91 }
 92 
 93-PROMPT_HOST='%{%b%F{gray}%K{black}%} %(?.%{%F{green}%}✔.%{%F{red}%}✘)%{%F{gray}%} %m %{%F{black}%}'
 94-PROMPT_DIR='%{%F{white}%} %1~ '
 95-PROMPT_SU='%(!.%{%k%F{blue}%K{black}%}⮀%{%F{yellow}%} ⚡ %{%k%F{black}%}.%{%k%F{blue}%})⮀%{%f%k%b%}'
 96+## Main prompt
 97+function build_prompt() {
 98+  RETVAL=$?
 99+  prompt_status
100+  prompt_context
101+  prompt_dir
102+  prompt_git
103+  segment_stop
104+}