jonathan.zsh-theme 3.8 KB

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