jonathan.zsh-theme 4.0 KB

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