jonathan.zsh-theme 4.1 KB

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