simonoff.zsh-theme 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. function theme_precmd {
  2. PR_FILLBAR=""
  3. PR_PWDLEN=""
  4. local promptsize=${#${(%):--(%n@%M:)--(%l)-}}
  5. local pwdsize=${#${(%):-%~}}
  6. local gitbranchsize="${#${(%)$(git_prompt_info)}:-}"
  7. local rvmpromptsize="${#${(%)$(ruby_prompt_info):-}}"
  8. # Truncate the path if it's too long.
  9. if (( promptsize + pwdsize + rvmpromptsize + gitbranchsize > COLUMNS )); then
  10. (( PR_PWDLEN = COLUMNS - promptsize ))
  11. else
  12. PR_FILLBAR="\${(l.$(( COLUMNS - (promptsize + pwdsize + rvmpromptsize + gitbranchsize) ))..${PR_SPACE}.)}"
  13. fi
  14. }
  15. function theme_preexec {
  16. setopt local_options extended_glob
  17. if [[ "$TERM" == "screen" ]]; then
  18. local CMD=${1[(wr)^(*=*|sudo|-*)]}
  19. echo -n "\ek$CMD\e\\"
  20. fi
  21. if [[ "$TERM" == "xterm" ]]; then
  22. print -Pn "\e]0;$1\a"
  23. fi
  24. if [[ "$TERM" == "rxvt" ]]; then
  25. print -Pn "\e]0;$1\a"
  26. fi
  27. }
  28. autoload -U add-zsh-hook
  29. add-zsh-hook precmd theme_precmd
  30. add-zsh-hook preexec theme_preexec
  31. # Set the prompt
  32. # Need this so the prompt will work.
  33. setopt prompt_subst
  34. # See if we can use colors.
  35. autoload zsh/terminfo
  36. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
  37. typeset -g PR_$color="%{$terminfo[bold]$fg[${(L)color}]%}"
  38. typeset -g PR_LIGHT_$color="%{$fg[${(L)color}]%}"
  39. done
  40. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  41. # Use extended characters to look nicer
  42. PR_HBAR="-"
  43. PR_ULCORNER="-"
  44. PR_LLCORNER="-"
  45. PR_LRCORNER="-"
  46. PR_URCORNER="-"
  47. # Modify Git prompt
  48. ZSH_THEME_GIT_PROMPT_PREFIX=" ["
  49. ZSH_THEME_GIT_PROMPT_SUFFIX="]"
  50. # Modify RVM prompt
  51. ZSH_THEME_RUBY_PROMPT_PREFIX=" ["
  52. ZSH_THEME_RUBY_PROMPT_SUFFIX="]"
  53. # Decide if we need to set titlebar text.
  54. case $TERM in
  55. xterm*|*rxvt*)
  56. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(ruby_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
  57. ;;
  58. screen)
  59. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  60. ;;
  61. *)
  62. PR_TITLEBAR=""
  63. ;;
  64. esac
  65. # Decide whether to set a screen title
  66. if [[ "$TERM" == "screen" ]]; then
  67. PR_STITLE=$'%{\ekzsh\e\\%}'
  68. else
  69. PR_STITLE=""
  70. fi
  71. # Finally, the prompt.
  72. PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
  73. $PR_RED$PR_HBAR<\
  74. $PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(ruby_prompt_info)\
  75. $PR_RED>$PR_HBAR${(e)PR_FILLBAR}\
  76. $PR_RED$PR_HBAR<\
  77. $PR_GREEN%l$PR_RED>$PR_HBAR\
  78. $PR_RED$PR_HBAR<\
  79. %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
  80. $PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
  81. $PR_NO_COLOUR '