trapd00r.zsh-theme 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 has a zsh version of
  5. # the previously used perl script 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=$'\e[m'
  23. local c1=$'\e[38;5;245m'
  24. local c2=$'\e[38;5;250m'
  25. local c3=$'\e[38;5;242m'
  26. local c4=$'\e[38;5;197m'
  27. local c5=$'\e[38;5;225m'
  28. local c6=$'\e[38;5;240m'
  29. local c7=$'\e[38;5;242m'
  30. local c8=$'\e[38;5;244m'
  31. local c9=$'\e[38;5;162m'
  32. local c10=$'\e[1m'
  33. local c11=$'\e[38;5;208m\e[1m'
  34. local c12=$'\e[38;5;142m\e[1m'
  35. local c13=$'\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 dir i=1
  48. for dir (${(s:/:)PWD}); do
  49. if [[ $i -eq 1 ]]; then
  50. if [[ $colors -ge 256 ]]; then
  51. print -Pn "%F{065}%B /%b"
  52. else
  53. print -Pn "\e[31;1m /"
  54. fi
  55. else
  56. if [[ $colors -ge 256 ]]; then
  57. print -Pn "${yellow[$i]:-%f} » "
  58. else
  59. print -Pn "%F{yellow} > "
  60. fi
  61. fi
  62. (( i++ ))
  63. if [[ $colors -ge 256 ]]; then
  64. print -Pn "%F{065}$dir"
  65. else
  66. print -Pn "%F{blue}$dir"
  67. fi
  68. done
  69. print -Pn "%f"
  70. }
  71. # We don't want to use the extended colorset in the TTY / VC.
  72. if [ "$TERM" = linux ]; then
  73. c1=$'\e[34;1m'
  74. c2=$'\e[35m'
  75. c3=$'\e[31m'
  76. c4=$'\e[31;1m'
  77. c5=$'\e[32m'
  78. c6=$'\e[32;1m'
  79. c7=$'\e[33m'
  80. c8=$'\e[33;1m'
  81. c9=$'\e[34m'
  82. c11=$'\e[35;1m'
  83. c12=$'\e[36m'
  84. c13=$'\e[31;1m'
  85. fi
  86. zstyle ':vcs_info:*' actionformats \
  87. '%{$c8%}(%f%s)%{$c7%}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
  88. zstyle ':vcs_info:*' formats \
  89. "%{$c8%}%s%%{$c7%}❨ %{$c9%}%{$c11%}%b%{$c7%} ❩%{$reset_color%}%f "
  90. zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
  91. zstyle ':vcs_info:*' enable git
  92. add-zsh-hook precmd prompt_jnrowe_precmd
  93. prompt_jnrowe_precmd () {
  94. vcs_info
  95. if [ "${vcs_info_msg_0_}" = "" ]; then
  96. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  97. PROMPT='${dir_status} ${ret_status}%{$reset_color%}
  98. > '
  99. # modified, to be committed
  100. elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then
  101. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  102. PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%}
  103. ${dir_status}%{$reset_color%}
  104. > '
  105. elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then
  106. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  107. PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%}
  108. ${dir_status}%{$reset_color%}
  109. %{$c13%}>%{$c0%} '
  110. else
  111. dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
  112. PROMPT='${vcs_info_msg_0_}
  113. ${dir_status}%{$reset_color%}
  114. > '
  115. fi
  116. }