77045230f4e2c80f4f312fbbeeb8583a41aa5a92
Author Philip Hofstetter <phofstetter@sensational.ch> Committer Philip Hofstetter <phofstetter@sensational.ch> Date 2011-12-28 14:58 UTC
Message make pygmalion theme use two lines when needed
if the length of the prompt (excluding color escapes) exceeds 40
characters, emit the arrow prompt on its own line
This helps a lot on smaller terminals
Diff 1 diff --git a/themes/pygmalion.zsh-theme b/themes/pygmalion.zsh-theme
2 index cf3bb908f217a9ed67228963609306da6aa8065d..435c0583062f1b834b5d403f4c33e6edb90166fa 100644
3 --- a/themes/pygmalion.zsh-theme
4 +++ b/themes/pygmalion.zsh-theme
5 @@ -1,9 +1,34 @@
6 # Yay! High voltage and arrows!
7
8 -ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
9 -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
10 -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
11 -ZSH_THEME_GIT_PROMPT_CLEAN=""
12 +prompt_setup_pygmalion(){
13 + ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
14 + ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
15 + ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
16 + ZSH_THEME_GIT_PROMPT_CLEAN=""
17 +
18 + 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%}'
19 + post_prompt='%{$fg[cyan]%}⇒%{$reset_color%} '
20 +
21 + base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
22 + post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
23 +
24 + add-zsh-hook precmd prompt_pygmalion_precmd
25 +}
26 +
27 +prompt_pygmalion_precmd(){
28 + local gitinfo=$(git_prompt_info)
29 + local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
30 + local exp_nocolor=$(print -P "$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor")
31 + local prompt_length=${#exp_nocolor}
32 +
33 + local nl=""
34 +
35 + if [[ $prompt_length -gt 40 ]]; then
36 + nl=$'\n%{\r%}';
37 + fi
38 + PROMPT="$base_prompt$gitinfo$nl$post_prompt"
39 +}
40 +
41 +prompt_setup_pygmalion
42
43 -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%} '
44