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