trapd00r.zsh-theme 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # trapd00r.zsh-theme
  2. #
  3. # This theme needs a terminal supporting 256 colors as well as unicode.
  4. # In order to avoid external dependencies, it also embeds a (possibly old)
  5. # copy of the perl script located at https://github.com/trapd00r/utils/blob/master/zsh_path,
  6. # which splits up the current path and makes it fancy.
  7. #
  8. # By default it spans over two lines like so:
  9. #
  10. # scp1@shiva:pts/9-> /home » scp1 (0)
  11. # >
  12. #
  13. # that's user@host:pts/-> splitted path (return status)
  14. #
  15. # If the current directory is a git repository, we span 3 lines;
  16. #
  17. # git❨ master ❩ DIRTY
  18. # scp1@shiva:pts/4-> /home » scp1 » dev » utils (0)
  19. # >
  20. autoload -U add-zsh-hook
  21. autoload -Uz vcs_info
  22. local c0=$( printf "\e[m")
  23. local c1=$( printf "\e[38;5;245m")
  24. local c2=$( printf "\e[38;5;250m")
  25. local c3=$( printf "\e[38;5;242m")
  26. local c4=$( printf "\e[38;5;197m")
  27. local c5=$( printf "\e[38;5;225m")
  28. local c6=$( printf "\e[38;5;240m")
  29. local c7=$( printf "\e[38;5;242m")
  30. local c8=$( printf "\e[38;5;244m")
  31. local c9=$( printf "\e[38;5;162m")
  32. local c10=$(printf "\e[1m")
  33. local c11=$(printf "\e[38;5;208m\e[1m")
  34. local c12=$(printf "\e[38;5;142m\e[1m")
  35. local c13=$(printf "\e[38;5;196m\e[1m")
  36. zsh_path() {
  37. local colors
  38. colors=$(echoti colors)
  39. local -A yellow
  40. yellow=(
  41. 1 '%F{228}' 2 '%F{222}' 3 '%F{192}' 4 '%F{186}'
  42. 5 '%F{227}' 6 '%F{221}' 7 '%F{191}' 8 '%F{185}'
  43. 9 '%F{226}' 10 '%F{220}' 11 '%F{190}' 12 '%F{184}'
  44. 13 '%F{214}' 14 '%F{178}' 15 '%F{208}' 16 '%F{172}'
  45. 17 '%F{202}' 18 '%F{166}'
  46. )
  47. local c i=1
  48. for c (${(s::)PWD}); do
  49. if [[ $c = "/" ]]; then
  50. if [[ $i -eq 1 ]]; then
  51. if [[ $colors -ge 256 ]]; then
  52. print -Pn "%F{065}%B /%b"
  53. else
  54. print -Pn "\e[31;1m /"
  55. fi
  56. (( i++ ))
  57. continue
  58. fi
  59. if [[ $colors -ge 256 ]]; then
  60. print -Pn "${yellow[$i]:-%f} » "
  61. else
  62. print -Pn "%F{yellow} > "
  63. fi
  64. (( i += 6 ))
  65. else
  66. if [[ $colors -ge 256 ]]; then
  67. print -Pn "%F{065}$c"
  68. else
  69. print -Pn "%F{blue}$c"
  70. fi
  71. fi
  72. done
  73. print -Pn "%f"
  74. }
  75. # We don't want to use the extended colorset in the TTY / VC.
  76. if [ "$TERM" = "linux" ]; then
  77. c1=$( printf "\e[34;1m")
  78. c2=$( printf "\e[35m")
  79. c3=$( printf "\e[31m")
  80. c4=$( printf "\e[31;1m")
  81. c5=$( printf "\e[32m")
  82. c6=$( printf "\e[32;1m")
  83. c7=$( printf "\e[33m")
  84. c8=$( printf "\e[33;1m")
  85. c9=$( printf "\e[34m")
  86. c11=$(printf "\e[35;1m")
  87. c12=$(printf "\e[36m")
  88. c13=$(printf "\e[31;1m")
  89. fi
  90. zstyle ':vcs_info:*' actionformats \
  91. '%{$c8%}(%f%s)%{$c7%}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
  92. zstyle ':vcs_info:*' formats \
  93. "%{$c8%}%s%%{$c7%}❨ %{$c9%}%{$c11%}%b%{$c7%} ❩%{$reset_color%}%f "
  94. zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
  95. zstyle ':vcs_info:*' enable git
  96. add-zsh-hook precmd prompt_jnrowe_precmd
  97. prompt_jnrowe_precmd () {
  98. vcs_info
  99. if [ "${vcs_info_msg_0_}" = "" ]; then
  100. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  101. PROMPT='%{$fg_bold[green]%}%p%{$reset_color%}${vcs_info_msg_0_}${dir_status} ${ret_status}%{$reset_color%}
  102. > '
  103. # modified, to be committed
  104. elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then
  105. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  106. PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%}
  107. %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
  108. > '
  109. elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then
  110. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  111. PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%}
  112. %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
  113. %{$c13%}>%{$c0%} '
  114. else
  115. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  116. PROMPT='${vcs_info_msg_0_}
  117. %{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%}
  118. > '
  119. fi
  120. }
  121. # vim: set ft=zsh sw=2 et tw=0: