aa99472c8ac5bdd111ea306e800bb152fb8580ac

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

style(simonoff): fix code style and optimize use of variables

Diff

This diff is truncated to protect this page.

  1diff --git a/themes/simonoff.zsh-theme b/themes/simonoff.zsh-theme
  2index fea2eff4276e59a8ed119518901de6445262318a..c906192a05ab83be0a357e0e4da8fe3a57dde0ba 100644
  3--- a/themes/simonoff.zsh-theme
  4+++ b/themes/simonoff.zsh-theme
  5@@ -1,43 +1,22 @@
  6-# Prompt
  7-#
  8-# Below are the color init strings for the basic file types. A color init
  9-# string consists of one or more of the following numeric codes:
 10-# Attribute codes:
 11-# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
 12-# Text color codes:
 13-# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
 14-# Background color codes:
 15-# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
 16-function precmd {
 17-
 18-  local TERMWIDTH
 19-  (( TERMWIDTH = ${COLUMNS} - 1 ))
 20-
 21-
 22-  ###
 23-  # Truncate the path if it's too long.
 24-
 25+function theme_precmd {
 26   PR_FILLBAR=""
 27   PR_PWDLEN=""
 28 
 29-  local promptsize=${#${(%):---(%n@%M:%l)---()}}
 30+  local promptsize=${#${(%):--(%n@%M:)--(%l)-}}
 31   local pwdsize=${#${(%):-%~}}
 32-  local gitbranch="$(git_prompt_info)"
 33-  local rvmprompt="$(ruby_prompt_info)"
 34-  local gitbranchsize=${#${gitbranch:-''}}
 35-  local rvmpromptsize=${#${rvmprompt:-''}}
 36+  local gitbranchsize="${#${(%)$(git_prompt_info)}:-}"
 37+  local rvmpromptsize="${#${(%)$(ruby_prompt_info):-}}"
 38 
 39-  if [[ "$promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize" -gt $TERMWIDTH ]]; then
 40-    ((PR_PWDLEN=$TERMWIDTH - $promptsize))
 41+  # Truncate the path if it's too long.
 42+  if (( promptsize + pwdsize + rvmpromptsize + gitbranchsize > COLUMNS )); then
 43+    (( PR_PWDLEN = COLUMNS - promptsize ))
 44   else
 45-    PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize)))..${PR_SPACE}.)}"
 46+    PR_FILLBAR="\${(l.$(( COLUMNS - (promptsize + pwdsize + rvmpromptsize + gitbranchsize) ))..${PR_SPACE}.)}"
 47   fi
 48 }
 49 
 50-
 51-setopt extended_glob
 52-
 53-preexec () {
 54+function theme_preexec {
 55+  setopt local_options extended_glob
 56   if [[ "$TERM" == "screen" ]]; then
 57     local CMD=${1[(wr)^(*=*|sudo|-*)]}
 58     echo -n "\ek$CMD\e\\"
 59@@ -53,47 +32,41 @@ preexec () {
 60 
 61 }
 62 
 63-setprompt () {
 64-###
 65-# Need this so the prompt will work.
 66+autoload -U add-zsh-hook
 67+add-zsh-hook precmd  theme_precmd
 68+add-zsh-hook preexec theme_preexec
 69 
 70-  setopt prompt_subst
 71 
 72+# Set the prompt
 73+
 74+# Need this so the prompt will work.
 75+setopt prompt_subst
 76 
 77-###
 78 # See if we can use colors.
 79+autoload zsh/terminfo
 80+for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
 81+  print -v "PR_$color" "%{$terminfo[bold]$fg[${(L)color}]%}"
 82+  print -v "PR_LIGHT_$color" "%{$fg[${(L)color}]%}"
 83+done
 84+PR_NO_COLOUR="%{$terminfo[sgr0]%}"
 85+
 86+# Use extended characters to look nicer
 87+PR_HBAR="-"
 88+PR_ULCORNER="-"
 89+PR_LLCORNER="-"
 90+PR_LRCORNER="-"
 91+PR_URCORNER="-"
 92+
 93+# Modify Git prompt
 94+ZSH_THEME_GIT_PROMPT_PREFIX=" ["
 95+ZSH_THEME_GIT_PROMPT_SUFFIX="]"
 96+
 97+# Modify RVM prompt
 98+ZSH_THEME_RUBY_PROMPT_PREFIX=" ["
 99+ZSH_THEME_RUBY_PROMPT_SUFFIX="]"
100 
101-  autoload zsh/terminfo
102-  for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
103-  eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
104-  eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'