prompt_frost_setup 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #
  2. # All information at your chilly fingertips.
  3. #
  4. # https://gist.github.com/TomFrost/9472926
  5. #
  6. # Authors:
  7. # Tom Frost <tom@frosteddesign.com>
  8. # Stefano Mazzucco <stefano@curso.re>
  9. #
  10. # Screenshots:
  11. # http://i.tomfro.st/U1Kov.png
  12. #
  13. # Dependencies
  14. pmodload 'helper'
  15. function prompt_frost_precmd {
  16. setopt LOCAL_OPTIONS
  17. unsetopt XTRACE KSH_ARRAYS
  18. if (( $+functions[git-info] )); then
  19. git-info
  20. fi
  21. if (( $+functions[python-info] )); then
  22. python-info
  23. fi
  24. if (( $+functions[battery-info] )); then
  25. battery-info
  26. fi
  27. }
  28. function prompt_frost_setup {
  29. setopt LOCAL_OPTIONS
  30. unsetopt XTRACE KSH_ARRAYS
  31. prompt_opts=(cr percent subst)
  32. # Load required functions.
  33. autoload -Uz add-zsh-hook
  34. autoload -Uz vcs_info
  35. # Add hook for calling vcs_info before each command.
  36. add-zsh-hook precmd prompt_frost_precmd
  37. # Tell prezto we can manage this prompt
  38. zstyle ':prezto:module:prompt' managed 'yes'
  39. _prompt_frost_nocolor="%{$terminfo[sgr0]%}%f"
  40. typeset -A _prompt_frost_colors
  41. _prompt_frost_colors[normalcyan]="${_prompt_frost_nocolor}%F{cyan}"
  42. _prompt_frost_colors[boldblue]="${_prompt_frost_nocolor}%F{blue}%{$terminfo[bold]%}"
  43. _prompt_frost_colors[normalgreen]="${_prompt_frost_nocolor}%F{green}"
  44. _prompt_frost_colors[boldgreen]="${_prompt_frost_nocolor}%F{green}%{$terminfo[bold]%}"
  45. _prompt_frost_colors[normalred]="${_prompt_frost_nocolor}%F{red}"
  46. _prompt_frost_colors[boldred]="${_prompt_frost_nocolor}%F{red}%{$terminfo[bold]%}"
  47. _prompt_frost_colors[normalyellow]="${_prompt_frost_nocolor}%F{yellow}"
  48. _prompt_frost_colors[boldyellow]="${_prompt_frost_nocolor}%F{yellow}%{$terminfo[bold]%}"
  49. # Set editor-info params
  50. zstyle ':prezto:module:editor:info:completing' format '${_prompt_frost_colors[normalred]}...${_prompt_frost_nocolor}'
  51. local prim
  52. [[ $TERM = "xterm"* ]] && prim='➤' || prim='▶'
  53. zstyle ':prezto:module:editor:info:keymap:primary' format $prim
  54. local ovr
  55. [[ $TERM = "xterm"* ]] && ovr='♺' || ovr='◘'
  56. zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format $ovr
  57. local alt
  58. [[ $TERM = "xterm"* ]] && alt='⍟' || alt='○'
  59. zstyle ':prezto:module:editor:info:keymap:alternate' format $alt
  60. # Set get-info parameters
  61. zstyle ':prezto:module:git:info' verbose 'yes'
  62. zstyle ':prezto:module:git:info:action' format "${_prompt_frost_colors[normalcyan]}∙${_prompt_frost_colors[normalyellow]}%s${_prompt_frost_nocolor}"
  63. local gitadded
  64. [[ $TERM = "xterm"* ]] && gitadded='✚' || gitadded='┼'
  65. zstyle ':prezto:module:git:info:added' format "${_prompt_frost_colors[boldgreen]} $gitadded${_prompt_frost_nocolor}"
  66. local gitahead
  67. [[ $TERM = "xterm"* ]] && gitahead='⚡' || gitahead='▲'
  68. zstyle ':prezto:module:git:info:ahead' format "${_prompt_frost_colors[boldyellow]} $gitahead${_prompt_frost_nocolor}"
  69. local gitbehind
  70. [[ $TERM = "xterm"* ]] && gitbehind='↯' || gitbehind='▼'
  71. zstyle ':prezto:module:git:info:behind' format "${_prompt_frost_colors[boldyellow]} ↯${_prompt_frost_nocolor}"
  72. zstyle ':prezto:module:git:info:branch' format "${_prompt_frost_colors[normalcyan]}∙${_prompt_frost_colors[boldyellow]}%b${_prompt_frost_nocolor}"
  73. zstyle ':prezto:module:git:info:tag' format "${_prompt_frost_colors[normalcyan]}∙${_prompt_frost_colors[normalred]}%t${_prompt_frost_nocolor}"
  74. local gitclean
  75. [[ $TERM = "xterm"* ]] && gitclean='✔' || gitclean='≡'
  76. zstyle ':prezto:module:git:info:clean' format "${_prompt_frost_colors[normalgreen]}$gitclean${_prompt_frost_nocolor}"
  77. zstyle ':prezto:module:git:info:commit' format "${_prompt_frost_colors[boldblue]}%.7c${_prompt_frost_nocolor}"
  78. local gitdeleted
  79. [[ $TERM = "xterm"* ]] && gitdeleted='✖' || gitdeleted='‼'
  80. zstyle ':prezto:module:git:info:deleted' format "${_prompt_frost_colors[boldred]} $gitdeleted${_prompt_frost_nocolor}"
  81. local gitmodified
  82. [[ $TERM = "xterm"* ]] && gitmodified='✱' || gitmodified='≈'
  83. zstyle ':prezto:module:git:info:modified' format "${_prompt_frost_colors[normalyellow]} $gitmodified${_prompt_frost_nocolor}"
  84. local gitrenamed
  85. [[ $TERM = "xterm"* ]] && gitrenamed='➜' || gitrenamed='→'
  86. zstyle ':prezto:module:git:info:renamed' format "${_prompt_frost_colors[boldred]} $gitrenamed${_prompt_frost_nocolor}"
  87. local gitstashed
  88. [[ $TERM = "xterm"* ]] && gitstashed='✭' || gitstashed='↨'
  89. zstyle ':prezto:module:git:info:stashed' format "${_prompt_frost_colors[normalyellow]} $gitstashed${_prompt_frost_nocolor}"
  90. local gitunmerged
  91. [[ $TERM = "xterm"* ]] && gitunmerged='═' || gitunmerged='='
  92. zstyle ':prezto:module:git:info:unmerged' format "${_prompt_frost_colors[normalyellow]} $gitunmerged${_prompt_frost_nocolor}"
  93. local gituntracked
  94. [[ $TERM = "xterm"* ]] && gituntracked='▪' || gituntracked='▓'
  95. zstyle ':prezto:module:git:info:untracked' format "${_prompt_frost_colors[boldred]} $gituntracked${_prompt_frost_nocolor}"
  96. zstyle ':prezto:module:git:info:keys' format \
  97. 'status' "${_prompt_frost_colors[normalcyan]}<%c%b%t%s${_prompt_frost_colors[normalcyan]}∙%C%A%B%S%a%d%m%r%U%u${_prompt_frost_colors[normalcyan]}>-"
  98. # Set python-info parameters
  99. zstyle ':prezto:module:python:info:virtualenv' format "${_prompt_frost_colors[boldred]}[venv:${_prompt_frost_colors[normalred]}%v${_prompt_frost_colors[boldred]}]${_prompt_frost_colors[normalcyan]}-"
  100. # Set battery-info parameters
  101. zstyle ':prezto:module:battery:info:percent' format "${_prompt_frost_colors[boldblue]}%p${_prompt_frost_nocolor}"
  102. zstyle ':prezto:module:battery:info:red' format "${_prompt_frost_colors[normalred]}▂${_prompt_frost_nocolor}"
  103. zstyle ':prezto:module:battery:info:yellow' format "${_prompt_frost_colors[normalyellow]}▄${_prompt_frost_nocolor}"
  104. zstyle ':prezto:module:battery:info:green' format "${_prompt_frost_colors[normalgreen]}█${_prompt_frost_nocolor}"
  105. zstyle ':prezto:module:battery:info:arrow_up' format "${_prompt_frost_colors[normalyellow]}↑${_prompt_frost_nocolor}"
  106. zstyle ':prezto:module:battery:info:arrow_down' format "${_prompt_frost_colors[normalyellow]}↓${_prompt_frost_nocolor}"
  107. zstyle ':prezto:module:battery:info:keys' format \
  108. 'status' "${_prompt_frost_colors[normalcyan]}<%r%y%g%u%d%p${_prompt_frost_colors[normalcyan]}>"
  109. # Get the time
  110. local time="${_prompt_frost_colors[boldblue]}%T"
  111. # Remote hosts change colors
  112. if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
  113. local host="${_prompt_frost_colors[boldyellow]}%m" #SSH
  114. else
  115. local host="${_prompt_frost_colors[boldgreen]}%m" # no SSH
  116. fi
  117. local user="%(!.${_prompt_frost_colors[boldred]}.${_prompt_frost_colors[boldgreen]})%n"
  118. local promptcolor='%(!.${_prompt_frost_colors[boldred]}.${_prompt_frost_nocolor})'
  119. local diamond
  120. [[ $TERM = "xterm"* ]] && diamond="◇" || diamond="◆"
  121. diamond="${_prompt_frost_colors[normalcyan]}$diamond"
  122. local curveup
  123. [[ $TERM = "xterm"* ]] && curveup="╭" || curveup="┌"
  124. curveup="${_prompt_frost_colors[normalcyan]}$curveup"
  125. local curvedown
  126. [[ $TERM = "xterm"* ]] && curvedown="╰" || curvedown="└"
  127. curvedown="${_prompt_frost_colors[normalcyan]}$curvedown"
  128. local connector="${_prompt_frost_colors[normalcyan]}>-<"
  129. local open_bracket="${_prompt_frost_colors[normalcyan]}<"
  130. local close_bracket="${_prompt_frost_colors[normalcyan]}>"
  131. local dash="${_prompt_frost_colors[normalcyan]}-"
  132. local path="${_prompt_frost_colors[boldblue]}%~"
  133. local at="${_prompt_frost_colors[normalcyan]}@"
  134. local editr='%(?.${editor_info[keymap]}.%F{red} %?${editor_info[keymap]})'
  135. [[ -z $IN_NIX_SHELL ]] || local _prompt_frost_nix_shell="${_prompt_frost_colors[boldred]}[nix:${_prompt_frost_colors[normalred]}${name:-shell}${_prompt_frost_colors[boldred]}]${_prompt_frost_nocolor}${dash}"
  136. # Define prompts.
  137. PROMPT="
  138. ${curveup}${dash}${open_bracket}${user}${at}${host}${connector}${path}${close_bracket}${dash}"${_prompt_frost_nix_shell}'$python_info[virtualenv]'""'${git_info[status]}'"${diamond}
  139. ${curvedown}${dash}${promptcolor}"${editr}"${_prompt_frost_nocolor} "
  140. RPROMPT="%{$(echotc UP 1)%}${open_bracket}$time${close_bracket}${dash}"'${battery_info[status]}'"%{$(echotc DO 1)%}${_prompt_frost_nocolor}"
  141. SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
  142. }
  143. prompt_frost_setup "$@"