simonoff.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. typeset -A altchar
  59. # set -A altchar "${(s..)terminfo[acsc]}"
  60. PR_SET_CHARSET="%{$terminfo[enacs]%}"
  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. # Modify Git prompt
  68. ZSH_THEME_GIT_PROMPT_PREFIX=" ["
  69. ZSH_THEME_GIT_PROMPT_SUFFIX="]"
  70. ###
  71. # Modify RVM prompt
  72. ZSH_THEME_RUBY_PROMPT_PREFIX=" ["
  73. ZSH_THEME_RUBY_PROMPT_SUFFIX="]"
  74. ###
  75. # Decide if we need to set titlebar text.
  76. case $TERM in
  77. xterm*|*rxvt*)
  78. PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%M:%~ $(git_prompt_info) $(rvm_prompt_info) | ${COLUMNS}x${LINES} | %y\a%}'
  79. ;;
  80. screen)
  81. PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
  82. ;;
  83. *)
  84. PR_TITLEBAR=''
  85. ;;
  86. esac
  87. ###
  88. # Decide whether to set a screen title
  89. if [[ "$TERM" == "screen" ]]; then
  90. PR_STITLE=$'%{\ekzsh\e\\%}'
  91. else
  92. PR_STITLE=''
  93. fi
  94. ###
  95. # Finally, the prompt.
  96. #
  97. PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
  98. $PR_RED$PR_HBAR<\
  99. $PR_BLUE%(!.$PR_RED%SROOT%s.%n)$PR_GREEN@$PR_BLUE%M:$PR_GREEN%$PR_PWDLEN<...<%~$PR_CYAN$(git_prompt_info)$(rvm_prompt_info)\
  100. $PR_RED>$PR_HBAR$PR_SPACE${(e)PR_FILLBAR}\
  101. $PR_RED$PR_HBAR<\
  102. $PR_GREEN%l$PR_RED>$PR_HBAR\
  103. $PR_RED$PR_HBAR<\
  104. %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
  105. $PR_LIGHT_BLUE%(!.$PR_RED.$PR_WHITE)%#$PR_RED>$PR_HBAR\
  106. $PR_NO_COLOUR '
  107. }
  108. setprompt