]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/themes/jonathan.zsh-theme
e8c49088466b53ce36dcc3d8f688754acdcc21f0
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / themes / jonathan.zsh-theme
1 function theme_precmd {
2   local TERMWIDTH=$(( COLUMNS - ${ZLE_RPROMPT_INDENT:-1} ))
3
4   PR_FILLBAR=""
5   PR_PWDLEN=""
6
7   local promptsize=${#${(%):---(%n@%m:%l)---()--}}
8   local rubypromptsize=${#${(%)$(ruby_prompt_info)}}
9   local pwdsize=${#${(%):-%~}}
10
11   # Truncate the path if it's too long.
12   if (( promptsize + rubypromptsize + pwdsize > TERMWIDTH )); then
13     (( PR_PWDLEN = TERMWIDTH - promptsize ))
14   elif [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
15     PR_FILLBAR="\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${PR_HBAR}:)}"
16   else
17     PR_FILLBAR="${PR_SHIFT_IN}\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${altchar[q]:--}:)}${PR_SHIFT_OUT}"
18   fi
19 }
20
21 function theme_preexec {
22   setopt local_options extended_glob
23   if [[ "$TERM" = "screen" ]]; then
24     local CMD=${1[(wr)^(*=*|sudo|-*)]}
25     echo -n "\ek$CMD\e\\"
26   fi
27 }
28
29 autoload -U add-zsh-hook
30 add-zsh-hook precmd  theme_precmd
31 add-zsh-hook preexec theme_preexec
32
33
34 # Set the prompt
35
36 # Need this so the prompt will work.
37 setopt prompt_subst
38
39 # See if we can use colors.
40 autoload zsh/terminfo
41 for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
42   typeset -g PR_$color="%{$terminfo[bold]$fg[${(L)color}]%}"
43   typeset -g PR_LIGHT_$color="%{$fg[${(L)color}]%}"
44 done
45 PR_NO_COLOUR="%{$terminfo[sgr0]%}"
46
47 # Modify Git prompt
48 ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[green]%}"
49 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
50 ZSH_THEME_GIT_PROMPT_DIRTY=""
51 ZSH_THEME_GIT_PROMPT_CLEAN=""
52
53 ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} %{%G✚%}"
54 ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} %{%G✹%}"
55 ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} %{%G✖%}"
56 ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} %{%G➜%}"
57 ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} %{%G═%}"
58 ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} %{%G✭%}"
59
60 # Use extended characters to look nicer if supported.
61 if [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
62   PR_SET_CHARSET=""
63   PR_HBAR="─"
64   PR_ULCORNER="┌"
65   PR_LLCORNER="└"
66   PR_LRCORNER="┘"
67   PR_URCORNER="┐"
68 else
69   typeset -g -A altchar
70   set -A altchar ${(s..)terminfo[acsc]}
71   # Some stuff to help us draw nice lines
72   PR_SET_CHARSET="%{$terminfo[enacs]%}"
73   PR_SHIFT_IN="%{$terminfo[smacs]%}"
74   PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
75   PR_HBAR="${PR_SHIFT_IN}${altchar[q]:--}${PR_SHIFT_OUT}"
76   PR_ULCORNER="${PR_SHIFT_IN}${altchar[l]:--}${PR_SHIFT_OUT}"
77   PR_LLCORNER="${PR_SHIFT_IN}${altchar[m]:--}${PR_SHIFT_OUT}"
78   PR_LRCORNER="${PR_SHIFT_IN}${altchar[j]:--}${PR_SHIFT_OUT}"
79   PR_URCORNER="${PR_SHIFT_IN}${altchar[k]:--}${PR_SHIFT_OUT}"
80 fi
81
82 # Decide if we need to set titlebar text.
83 case $TERM in
84   xterm*)
85     PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
86     ;;
87   screen)
88     PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
89     ;;
90   *)
91     PR_TITLEBAR=""
92     ;;
93 esac
94
95 # Decide whether to set a screen title
96 if [[ "$TERM" = "screen" ]]; then
97   PR_STITLE=$'%{\ekzsh\e\\%}'
98 else
99   PR_STITLE=""
100 fi
101
102 # Finally, the prompt.
103 PROMPT='${PR_SET_CHARSET}${PR_STITLE}${(e)PR_TITLEBAR}\
104 ${PR_CYAN}${PR_ULCORNER}${PR_HBAR}${PR_GREY}(\
105 ${PR_GREEN}%${PR_PWDLEN}<...<%~%<<\
106 ${PR_GREY})$(ruby_prompt_info)${PR_CYAN}${PR_HBAR}${PR_HBAR}${(e)PR_FILLBAR}${PR_HBAR}${PR_GREY}(\
107 ${PR_CYAN}%(!.%SROOT%s.%n)${PR_GREY}@${PR_GREEN}%m:%l\
108 ${PR_GREY})${PR_CYAN}${PR_HBAR}${PR_URCORNER}\
109
110 ${PR_CYAN}${PR_LLCORNER}${PR_BLUE}${PR_HBAR}(\
111 ${PR_YELLOW}%D{%H:%M:%S}\
112 ${PR_LIGHT_BLUE}%{$reset_color%}$(git_prompt_info)$(git_prompt_status)${PR_BLUE})${PR_CYAN}${PR_HBAR}\
113 ${PR_HBAR}\
114 >${PR_NO_COLOUR} '
115
116 # display exitcode on the right when > 0
117 return_code="%(?..%{$fg[red]%}%? ↵ %{$reset_color%})"
118 RPROMPT=' $return_code${PR_CYAN}${PR_HBAR}${PR_BLUE}${PR_HBAR}\
119 (${PR_YELLOW}%D{%a,%b%d}${PR_BLUE})${PR_HBAR}${PR_CYAN}${PR_LRCORNER}${PR_NO_COLOUR}'
120
121 PS2='${PR_CYAN}${PR_HBAR}\
122 ${PR_BLUE}${PR_HBAR}(\
123 ${PR_LIGHT_GREEN}%_${PR_BLUE})${PR_HBAR}\
124 ${PR_CYAN}${PR_HBAR}${PR_NO_COLOUR} '