eriner.zsh-theme 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # vim:et sts=2 sw=2 ft=zsh
  2. #
  3. # Eriner's Theme - fork of agnoster
  4. # A Powerline-inspired theme for ZSH
  5. #
  6. # In order for this theme to render correctly, a font with Powerline symbols is
  7. # required. A simple way to install a font with Powerline symbols is to follow
  8. # the instructions here: https://github.com/powerline/fonts#installation
  9. #
  10. # The aim of this theme is to only show you *relevant* information. Like most
  11. # prompts, it will only show git information when in a git working directory.
  12. # However, it goes a step further: everything from the current user and
  13. # hostname to whether the last call exited with an error to whether background
  14. # jobs are running in this shell will all be displayed automatically when
  15. # appropriate.
  16. #
  17. # Requires the `git-info` zmodule to be included in the .zimrc file.
  18. prompt_eriner_help () {
  19. cat <<EOH
  20. This prompt is color-scheme-able. You can customize it using:
  21. prompt eriner [status_color] [pwd_color] [git_clean_color] [git_dirty_color]
  22. where the parameters are the background colors for each segment. The default
  23. values are black, cyan, green, and yellow.
  24. In order for this prompt to render correctly, a font with Powerline symbols is
  25. required. A simple way to install a font with Powerline symbols is to follow
  26. the instructions here: https://github.com/powerline/fonts#installation
  27. EOH
  28. }
  29. prompt_eriner_main() {
  30. local prompt_eriner_retval=${?}
  31. local prompt_eriner_color1=${1:-black}
  32. local prompt_eriner_color2=${2:-cyan}
  33. ### Segment drawing
  34. # Utility functions to make it easy and re-usable to draw segmented prompts.
  35. local prompt_eriner_bg
  36. # Begin a segment. Takes two arguments, background color and contents of the
  37. # new segment.
  38. prompt_eriner_segment() {
  39. print -n "%K{${1}}"
  40. [[ -n ${prompt_eriner_bg} ]] && print -n "%F{${prompt_eriner_bg}}"
  41. print -n "${2}"
  42. prompt_eriner_bg=${1}
  43. }
  44. prompt_eriner_standout_segment() {
  45. print -n "%S%F{${1}}"
  46. [[ -n ${prompt_eriner_bg} ]] && print -n "%K{${prompt_eriner_bg}}%k"
  47. print -n "${2}%s"
  48. prompt_eriner_bg=${1}
  49. }
  50. # End the prompt, closing last segment.
  51. prompt_eriner_end() {
  52. print -n "%k%F{${prompt_eriner_bg}}%f "
  53. }
  54. ### Prompt components
  55. # Each component will draw itself, or hide itself if no information needs to
  56. # be shown.
  57. # Status: Was there an error? Am I root? Are there background jobs? Ranger
  58. # spawned shell? Who and where am I (user@hostname)?
  59. prompt_eriner_status() {
  60. local segment=''
  61. (( prompt_eriner_retval )) && segment+=' %F{red}✘'
  62. (( UID == 0 )) && segment+=' %F{yellow}⚡'
  63. (( $(jobs -l | wc -l) )) && segment+=' %F{cyan}⚙'
  64. (( RANGER_LEVEL )) && segment+=' %F{cyan}r'
  65. if [[ ${USER} != ${DEFAULT_USER} || -n ${SSH_CLIENT} ]]; then
  66. segment+=" %F{%(!.yellow.default)}${USER}@%m"
  67. fi
  68. if [[ -n ${segment} ]]; then
  69. prompt_eriner_segment ${prompt_eriner_color1} "${segment} "
  70. fi
  71. }
  72. # Pwd: current working directory.
  73. prompt_eriner_pwd() {
  74. prompt_eriner_standout_segment ${prompt_eriner_color2} " $(short_pwd) "
  75. }
  76. # Git: branch/detached head, dirty status.
  77. prompt_eriner_git() {
  78. if [[ -n ${git_info} ]]; then
  79. local indicator
  80. [[ ${git_info[color]} == yellow ]] && indicator=' ±'
  81. prompt_eriner_standout_segment ${git_info[color]} " ${(e)git_info[prompt]}${indicator} "
  82. fi
  83. }
  84. prompt_eriner_status
  85. prompt_eriner_pwd
  86. prompt_eriner_git
  87. prompt_eriner_end
  88. }
  89. prompt_eriner_precmd() {
  90. (( ${+functions[git-info]} )) && git-info
  91. }
  92. prompt_eriner_setup() {
  93. autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_eriner_precmd
  94. prompt_opts=(cr percent sp subst)
  95. local prompt_eriner_color3=${3:-green}
  96. local prompt_eriner_color4=${4:-yellow}
  97. zstyle ':zim:git-info:branch' format ' %b'
  98. zstyle ':zim:git-info:commit' format '➦ %c'
  99. zstyle ':zim:git-info:action' format ' (%s)'
  100. zstyle ':zim:git-info:clean' format ${prompt_eriner_color3}
  101. zstyle ':zim:git-info:dirty' format ${prompt_eriner_color4}
  102. zstyle ':zim:git-info:keys' format \
  103. 'prompt' '%b%c%s' \
  104. 'color' '%C%D'
  105. PS1="\$(prompt_eriner_main ${@:1:2})"
  106. RPS1=''
  107. }
  108. prompt_eriner_preview () {
  109. if (( ${#} )); then
  110. prompt_preview_theme eriner "${@}"
  111. else
  112. prompt_preview_theme eriner
  113. print
  114. prompt_preview_theme eriner black blue green yellow
  115. fi
  116. }
  117. prompt_eriner_setup "${@}"