jonathan.zsh-theme 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. typeset -A altchar
  57. set -A altchar ${(s..)terminfo[acsc]}
  58. PR_SET_CHARSET="%{$terminfo[enacs]%}"
  59. PR_SHIFT_IN="%{$terminfo[smacs]%}"
  60. PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
  61. PR_HBAR=${altchar[q]:--}
  62. PR_ULCORNER=${altchar[l]:--}
  63. PR_LLCORNER=${altchar[m]:--}
  64. PR_LRCORNER=${altchar[j]:--}
  65. PR_URCORNER=${altchar[k]:--}
  66. ###
  67. # Decide if we need to set titlebar text.
  68. case $TERM in
  69. xterm*)
  70. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
  71. ;;
  72. screen)
  73. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  74. ;;
  75. *)
  76. PR_TITLEBAR=''
  77. ;;
  78. esac
  79. ###
  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. ###
  87. # Finally, the prompt.
  88. PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
  89. $PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT$PR_GREY(\
  90. $PR_GREEN%$PR_PWDLEN<...<%~%<<\
  91. $PR_GREY)`rvm_prompt_info || rbenv_prompt_info`$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_HBAR${(e)PR_FILLBAR}$PR_HBAR$PR_SHIFT_OUT$PR_GREY(\
  92. $PR_CYAN%(!.%SROOT%s.%n)$PR_GREY@$PR_GREEN%m:%l\
  93. $PR_GREY)$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_URCORNER$PR_SHIFT_OUT\
  94. $PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
  95. $PR_YELLOW%D{%H:%M:%S}\
  96. $PR_LIGHT_BLUE%{$reset_color%}`git_prompt_info``git_prompt_status`$PR_BLUE)$PR_CYAN$PR_SHIFT_IN$PR_HBAR\
  97. $PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
  98. >$PR_NO_COLOUR '
  99. # display exitcode on the right when >0
  100. return_code="%(?..%{$fg[red]%}%? ↵ %{$reset_color%})"
  101. RPROMPT=' $return_code$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
  102. ($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'
  103. PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
  104. $PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
  105. $PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
  106. $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
  107. }
  108. setprompt
  109. autoload -U add-zsh-hook
  110. add-zsh-hook precmd theme_precmd
  111. add-zsh-hook preexec theme_preexec