simonoff.zsh-theme 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Prompt
  2. #
  3. # Below are the color init strings for the basic file types. A color init
  4. # string consists of one or more of the following numeric codes:
  5. # Attribute codes:
  6. # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
  7. # Text color codes:
  8. # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  9. # Background color codes:
  10. # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
  11. function precmd {
  12. local TERMWIDTH
  13. (( TERMWIDTH = ${COLUMNS} - 1 ))
  14. ###
  15. # Truncate the path if it's too long.
  16. PR_FILLBAR=""
  17. PR_PWDLEN=""
  18. local promptsize=${#${(%):---(%n@%M:%l)---()}}
  19. local pwdsize=${#${(%):-%~}}
  20. local gitbranch="$(git_prompt_info)"
  21. local rvmprompt="$(rvm_prompt_info)"
  22. local gitbranchsize=${#${gitbranch:-''}}
  23. local rvmpromptsize=${#${rvmprompt:-''}}
  24. if [[ "$promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize" -gt $TERMWIDTH ]]; then
  25. ((PR_PWDLEN=$TERMWIDTH - $promptsize))
  26. else
  27. PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $rvmpromptsize + $gitbranchsize)))..${PR_SPACE}.)}"
  28. fi
  29. }
  30. setopt extended_glob
  31. preexec () {
  32. if [[ "$TERM" == "screen" ]]; then
  33. local CMD=${1[(wr)^(*=*|sudo|-*)]}
  34. echo -n "\ek$CMD\e\\"
  35. fi
  36. if [[ "$TERM" == "xterm" ]]; then
  37. print -Pn "\e]0;$1\a"
  38. fi
  39. if [[ "$TERM" == "rxvt" ]]; then
  40. print -Pn "\e]0;$1\a"
  41. fi
  42. }
  43. setprompt () {
  44. ###
  45. # Need this so the prompt will work.
  46. setopt prompt_subst
  47. ###
  48. # See if we can use colors.
  49. autoload colors zsh/terminfo
  50. if [[ "$terminfo[colors]" -ge 8 ]]; then
  51. colors
  52. fi
  53. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  54. eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  55. eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  56. (( count = $count + 1 ))
  57. done
  58. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  59. ###
  60. # See if we can use extended characters to look nicer.
  61. typeset -A altchar
  62. # set -A altchar "${(s..)terminfo[acsc]}"
  63. PR_SET_CHARSET="%{$terminfo[enacs]%}"
  64. PR_HBAR=${altchar[q]:--}
  65. PR_ULCORNER=${altchar[l]:--}
  66. PR_LLCORNER=${altchar[m]:--}
  67. PR_LRCORNER=${altchar[j]:--}
  68. PR_URCORNER=${altchar[k]:--}
  69. ###
  70. # Modify Git prompt
  71. ZSH_THEME_GIT_PROMPT_PREFIX=" ["
  72. ZSH_THEME_GIT_PROMPT_SUFFIX="]"
  73. ###
  74. # Modify RVM prompt
  75. ZSH_THEME_RVM_PROMPT_PREFIX=" ["
  76. ZSH_THEME_RVM_PROMPT_SUFFIX="]"
  77. ###
  78. # Decide if we need to set titlebar text.
  79. case $TERM in
  80. xterm*|*rxvt*)
  81. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(rvm_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
  82. ;;
  83. screen)
  84. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  85. ;;
  86. *)
  87. PR_TITLEBAR=''
  88. ;;
  89. esac
  90. ###
  91. # Decide whether to set a screen title
  92. if [[ "$TERM" == "screen" ]]; then
  93. PR_STITLE=$'%{\ekzsh\e\\%}'
  94. else
  95. PR_STITLE=''
  96. fi
  97. ###
  98. # Finally, the prompt.
  99. #
  100. PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
  101. $PR_RED$PR_HBAR<\
  102. $PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(rvm_prompt_info)\
  103. $PR_RED>$PR_HBAR$PR_SPACE${(e)PR_FILLBAR}\
  104. $PR_RED$PR_HBAR<\
  105. $PR_GREEN%l$PR_RED>$PR_HBAR\
  106. $PR_RED$PR_HBAR<\
  107. %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
  108. $PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
  109. $PR_NO_COLOUR '
  110. }
  111. setprompt