浏览代码

Merge pull request #781 from pilif/two-lined-pygmalion

make pygmalion theme use two lines when needed
Robby Russell 11 年之前
父节点
当前提交
4954335b64
共有 1 个文件被更改,包括 30 次插入5 次删除
  1. 30 5
      themes/pygmalion.zsh-theme

+ 30 - 5
themes/pygmalion.zsh-theme

@@ -1,9 +1,34 @@
 # Yay! High voltage and arrows!
 
-ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
-ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
-ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_CLEAN=""
+prompt_setup_pygmalion(){
+  ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
+  ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
+  ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
+  ZSH_THEME_GIT_PROMPT_CLEAN=""
+
+  base_prompt='%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}'
+  post_prompt='%{$fg[cyan]%}⇒%{$reset_color%}  '
+
+  base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
+  post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
+
+  add-zsh-hook precmd prompt_pygmalion_precmd
+}
+
+prompt_pygmalion_precmd(){
+  local gitinfo=$(git_prompt_info)
+  local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
+  local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
+  local prompt_length=${#exp_nocolor}
+
+  local nl=""
+
+  if [[ $prompt_length -gt 40 ]]; then
+    nl=$'\n%{\r%}';
+  fi
+  PROMPT="$base_prompt$gitinfo$nl$post_prompt"
+}
+
+prompt_setup_pygmalion
 
-PROMPT='%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}$(git_prompt_info)%{$fg[cyan]%}⇒%{$reset_color%}  '