simonoff.zsh-theme 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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="$(ruby_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 zsh/terminfo
  50. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  51. eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  52. eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  53. (( count = $count + 1 ))
  54. done
  55. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  56. ###
  57. # See if we can use extended characters to look nicer.
  58. PR_HBAR=${altchar[q]:--}
  59. PR_ULCORNER=${altchar[l]:--}
  60. PR_LLCORNER=${altchar[m]:--}
  61. PR_LRCORNER=${altchar[j]:--}
  62. PR_URCORNER=${altchar[k]:--}
  63. ###
  64. # Modify Git prompt
  65. ZSH_THEME_GIT_PROMPT_PREFIX=" ["
  66. ZSH_THEME_GIT_PROMPT_SUFFIX="]"
  67. ###
  68. # Modify RVM prompt
  69. ZSH_THEME_RUBY_PROMPT_PREFIX=" ["
  70. ZSH_THEME_RUBY_PROMPT_SUFFIX="]"
  71. ###
  72. # Decide if we need to set titlebar text.
  73. case $TERM in
  74. xterm*|*rxvt*)
  75. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(rvm_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
  76. ;;
  77. screen)
  78. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  79. ;;
  80. *)
  81. PR_TITLEBAR=''
  82. ;;
  83. esac
  84. ###
  85. # Decide whether to set a screen title
  86. if [[ "$TERM" == "screen" ]]; then
  87. PR_STITLE=$'%{\ekzsh\e\\%}'
  88. else
  89. PR_STITLE=''
  90. fi
  91. ###
  92. # Finally, the prompt.
  93. #
  94. PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
  95. $PR_RED$PR_HBAR<\
  96. $PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(rvm_prompt_info)\
  97. $PR_RED>$PR_HBAR$PR_SPACE${(e)PR_FILLBAR}\
  98. $PR_RED$PR_HBAR<\
  99. $PR_GREEN%l$PR_RED>$PR_HBAR\
  100. $PR_RED$PR_HBAR<\
  101. %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
  102. $PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
  103. $PR_NO_COLOUR '
  104. }
  105. setprompt