Parent directory

simonoff.zsh-theme

2492 bytes
 1function theme_precmd {
 2  PR_FILLBAR=""
 3  PR_PWDLEN=""
 4
 5  local promptsize=${#${(%):--(%n@%M:)--(%l)-}}
 6  local pwdsize=${#${(%):-%~}}
 7  local gitbranchsize="${#${(%)$(git_prompt_info)}:-}"
 8  local rvmpromptsize="${#${(%)$(ruby_prompt_info):-}}"
 9
10  # Truncate the path if it's too long.
11  if (( promptsize + pwdsize + rvmpromptsize + gitbranchsize > COLUMNS )); then
12    (( PR_PWDLEN = COLUMNS - promptsize ))
13  else
14    PR_FILLBAR="\${(l.$(( COLUMNS - (promptsize + pwdsize + rvmpromptsize + gitbranchsize) ))..${PR_SPACE}.)}"
15  fi
16}
17
18function theme_preexec {
19  setopt local_options extended_glob
20  if [[ "$TERM" == "screen" ]]; then
21    local CMD=${1[(wr)^(*=*|sudo|-*)]}
22    echo -n "\ek$CMD\e\\"
23  fi
24
25  if [[ "$TERM" == "xterm" ]]; then
26    print -Pn "\e]0;$1\a"
27  fi
28
29  if [[ "$TERM" == "rxvt" ]]; then
30    print -Pn "\e]0;$1\a"
31  fi
32
33}
34
35autoload -U add-zsh-hook
36add-zsh-hook precmd  theme_precmd
37add-zsh-hook preexec theme_preexec
38
39
40# Set the prompt
41
42# Need this so the prompt will work.
43setopt prompt_subst
44
45# See if we can use colors.
46autoload zsh/terminfo
47for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
48  typeset -g PR_$color="%{$terminfo[bold]$fg[${(L)color}]%}"
49  typeset -g PR_LIGHT_$color="%{$fg[${(L)color}]%}"
50done
51PR_NO_COLOUR="%{$terminfo[sgr0]%}"
52
53# Use extended characters to look nicer
54PR_HBAR="-"
55PR_ULCORNER="-"
56PR_LLCORNER="-"
57PR_LRCORNER="-"
58PR_URCORNER="-"
59
60# Modify Git prompt
61ZSH_THEME_GIT_PROMPT_PREFIX=" ["
62ZSH_THEME_GIT_PROMPT_SUFFIX="]"
63
64# Modify RVM prompt
65ZSH_THEME_RUBY_PROMPT_PREFIX=" ["
66ZSH_THEME_RUBY_PROMPT_SUFFIX="]"
67
68# Decide if we need to set titlebar text.
69case $TERM in
70  xterm*|*rxvt*)
71    PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(ruby_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
72    ;;
73  screen)
74    PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
75    ;;
76  *)
77    PR_TITLEBAR=""
78    ;;
79esac
80
81# Decide whether to set a screen title
82if [[ "$TERM" == "screen" ]]; then
83  PR_STITLE=$'%{\ekzsh\e\\%}'
84else
85  PR_STITLE=""
86fi
87
88# Finally, the prompt.
89PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
90$PR_RED$PR_HBAR<\
91$PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(ruby_prompt_info)\
92$PR_RED>$PR_HBAR${(e)PR_FILLBAR}\
93$PR_RED$PR_HBAR<\
94$PR_GREEN%l$PR_RED>$PR_HBAR\
95
96$PR_RED$PR_HBAR<\
97%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
98$PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
99$PR_NO_COLOUR '