jonathan.zsh-theme 3.8 KB

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