]> git.rmz.io Git - dotfiles.git/blob - zsh/themes/simonoff.zsh-theme
update zshrc
[dotfiles.git] / zsh / themes / simonoff.zsh-theme
1 # Prompt
2 #
3 # Below are the color init strings for the basic file types. A color init
4 # string consists of one or more of the following numeric codes:
5 # Attribute codes:
6 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
7 # Text color codes:
8 # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
9 # Background color codes:
10 # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
11 function precmd {
12
13 local TERMWIDTH
14 (( TERMWIDTH = ${COLUMNS} - 1 ))
15
16
17 ###
18 # Truncate the path if it's too long.
19
20 PR_FILLBAR=""
21 PR_PWDLEN=""
22
23 local promptsize=${#${(%):---(%n@%M:%l)---()}}
24 local pwdsize=${#${(%):-%~}}
25 local gitbranch="$(git_prompt_info)"
26 local rvmprompt="$(rvm_prompt_info)"
27 local gitbranchsize=${#${gitbranch:-''}}
28 local rvmpromptsize=${#${rvmprompt:-''}}
29
30 if [[ "$promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize" -gt $TERMWIDTH ]]; then
31 ((PR_PWDLEN=$TERMWIDTH - $promptsize))
32 else
33 PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize)))..${PR_SPACE}.)}"
34 fi
35 }
36
37
38 setopt extended_glob
39
40 preexec () {
41 if [[ "$TERM" == "screen" ]]; then
42 local CMD=${1[(wr)^(*=*|sudo|-*)]}
43 echo -n "\ek$CMD\e\\"
44 fi
45
46 if [[ "$TERM" == "xterm" ]]; then
47 print -Pn "\e]0;$1\a"
48 fi
49
50 if [[ "$TERM" == "rxvt" ]]; then
51 print -Pn "\e]0;$1\a"
52 fi
53
54 }
55
56 setprompt () {
57 ###
58 # Need this so the prompt will work.
59
60 setopt prompt_subst
61
62
63 ###
64 # See if we can use colors.
65
66 autoload colors zsh/terminfo
67 if [[ "$terminfo[colors]" -ge 8 ]]; then
68 colors
69 fi
70 for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
71 eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
72 eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
73 (( count = $count + 1 ))
74 done
75 PR_NO_COLOUR="%{$terminfo[sgr0]%}"
76
77
78 ###
79 # See if we can use extended characters to look nicer.
80
81 typeset -A altchar
82 # set -A altchar "${(s..)terminfo[acsc]}"
83 PR_SET_CHARSET="%{$terminfo[enacs]%}"
84 PR_HBAR=${altchar[q]:--}
85 PR_ULCORNER=${altchar[l]:--}
86 PR_LLCORNER=${altchar[m]:--}
87 PR_LRCORNER=${altchar[j]:--}
88 PR_URCORNER=${altchar[k]:--}
89
90 ###
91 # Modify Git prompt
92 ZSH_THEME_GIT_PROMPT_PREFIX=" ["
93 ZSH_THEME_GIT_PROMPT_SUFFIX="]"
94 ###
95 # Modify RVM prompt
96 ZSH_THEME_RVM_PROMPT_PREFIX=" ["
97 ZSH_THEME_RVM_PROMPT_SUFFIX="]"
98
99
100 ###
101 # Decide if we need to set titlebar text.
102
103 case $TERM in
104 xterm*|*rxvt*)
105 PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(rvm_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
106 ;;
107 screen)
108 PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
109 ;;
110 *)
111 PR_TITLEBAR=''
112 ;;
113 esac
114
115
116 ###
117 # Decide whether to set a screen title
118 if [[ "$TERM" == "screen" ]]; then
119 PR_STITLE=$'%{\ekzsh\e\\%}'
120 else
121 PR_STITLE=''
122 fi
123
124 ###
125 # Finally, the prompt.
126 #
127 PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
128 $PR_RED$PR_HBAR<\
129 $PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(rvm_prompt_info)\
130 $PR_RED>$PR_HBAR$PR_SPACE${(e)PR_FILLBAR}\
131 $PR_RED$PR_HBAR<\
132 $PR_GREEN%l$PR_RED>$PR_HBAR\
133
134 $PR_RED$PR_HBAR<\
135 %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
136 $PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
137 $PR_NO_COLOUR '
138
139 }
140
141 setprompt