jonathan.zsh-theme 4.0 KB

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