prompt_kolter_setup 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #
  2. # A theme based on Steve Losh's Extravagant Prompt with vcs_info integration.
  3. #
  4. # Authors:
  5. # Steve Losh <steve@stevelosh.com>
  6. # Bart Trojanowski <bart@jukie.net>
  7. # Brian Carper <brian@carper.ca>
  8. # kolter <kolter@gmail.com>
  9. # Sorin Ionescu <sorin.ionescu@gmail.com>
  10. #
  11. # Screenshots:
  12. # http://i.imgur.com/HyRvv.png
  13. #
  14. function prompt_kolter_precmd {
  15. git-info
  16. }
  17. function prompt_kolter_preexec {
  18. if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then
  19. source <(tmux show-environment | sed -r -e '/^-/d' -e 's/^([^=]+)=(.*)$/\1="\2"/')
  20. fi
  21. }
  22. function prompt_kolter_setup {
  23. setopt LOCAL_OPTIONS
  24. unsetopt XTRACE KSH_ARRAYS
  25. prompt_opts=(cr percent subst)
  26. # Load required functions.
  27. autoload -Uz add-zsh-hook
  28. # Add hook for calling vcs_info before each command.
  29. add-zsh-hook precmd prompt_kolter_precmd
  30. add-zsh-hook precmd prompt_kolter_preexec
  31. # Use extended color pallete if available.
  32. if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
  33. _color_red="%F{196}"
  34. _color_green="%F{49}"
  35. _color_yellow="%F{226}"
  36. _color_blue="%F{21}"
  37. _color_magenta="%F{97}"
  38. _color_cyan="%F{26}"
  39. _color_white="%F{253}"
  40. _color_brightred="%F{197}"
  41. _color_brightgreen="%F{148}"
  42. _color_brightyellow="%F{228}"
  43. _color_brightblue="%F{39}"
  44. _color_brightmagenta="%F{139}"
  45. _color_brightcyan="%F{38}"
  46. _color_brightwhite="%F{231}"
  47. _color_reset="%f"
  48. else
  49. _color_red="%F{red}"
  50. _color_green="%F{green}"
  51. _color_yellow="%F{yellow}"
  52. _color_blue="%F{blue}"
  53. _color_magenta="%F{magenta}"
  54. _color_cyan="%F{cyan}"
  55. _color_white="%F{white}"
  56. _color_brightred="%B%F{red}"
  57. _color_brightgreen="%B%F{green}"
  58. _color_brightyellow="%B%F{yellow}"
  59. _color_brightblue="%B%F{blue}"
  60. _color_brightmagenta="%B%F{magenta}"
  61. _color_brightcyan="%B%F{cyan}"
  62. _color_brightwhite="%B%F{white}"
  63. _color_reset="%f"
  64. fi
  65. # In normal formats and actionformats the following replacements are done:
  66. # %s - The VCS in use (git, hg, svn, etc.).
  67. # %b - Information about the current branch.
  68. # %a - An identifier that describes the action. Only makes sense in actionformats.
  69. # %i - The current revision number or identifier. For hg the hgrevformat style may be used to customize the output.
  70. # %c - The string from the stagedstr style if there are staged changes in the repository.
  71. # %u - The string from the unstagedstr style if there are unstaged changes in the repository.
  72. # %R - The base directory of the repository.
  73. # %r - The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
  74. # %S - A subdirectory within a repository. If $PWD is /foo/bar/repoXY/beer/tasty, %S is beer/tasty.
  75. #
  76. # In branchformat these replacements are done:
  77. # %s - The VCS in use (git, hg, svn, etc.).
  78. # %b - Information about the current branch.
  79. # %a - An identifier that describes the action. Only makes sense in actionformats.
  80. # %i - The current revision number or identifier. For hg the hgrevformat style may be used to customize the output.
  81. # %c - The string from the stagedstr style if there are staged changes in the repository.
  82. # %u - The string from the unstagedstr style if there are unstaged changes in the repository.
  83. # %R - The base directory of the repository.
  84. # %r - The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
  85. # %S - A subdirectory within a repository. If $PWD is /foo/bar/repoXY/beer/tasty, %S is beer/tasty.
  86. local branch_format="${_color_brightyellow}%b${_color_reset} %u%c"
  87. local action_format="(${_color_green}%a${_color_reset})"
  88. local unstaged_format="${_color_brightred}●${_color_reset}"
  89. local staged_format="${_color_brightgreen}●${_color_reset}"
  90. # Set vcs_info parameters.
  91. zstyle ':vcs_info:*' enable svn git
  92. # If enabled, this style causes the %c and %u format escapes to show when the
  93. # working directory has uncommitted changes
  94. zstyle ':vcs_info:*:prompt:*' check-for-changes true
  95. # This string will be used in the %u escape if there are unstaged changes in
  96. # the repository
  97. zstyle ':vcs_info:*:prompt:*' unstagedstr "${unstaged_format}"
  98. # This string will be used in the %c escape if there are staged changes in
  99. # the repository
  100. zstyle ':vcs_info:*:prompt:*' stagedstr "${staged_format}"
  101. # A list of formats, used if there is a special action going on in your
  102. # current repository; like an interactive rebase or a merge conflict.
  103. zstyle ':vcs_info:*:prompt:*' actionformats "${branch_format}${action_format}"
  104. # A list of formats, used when actionformats is not used (which is most of
  105. # the time).
  106. zstyle ':vcs_info:*:prompt:*' formats " ${_color_brightwhite}on ${_color_brightcyan}%s${_color_brightwhite}:${branch_format}"
  107. # These "formats" are exported when we didn’t detect a version control system
  108. # for the current directory or vcs_info was disabled
  109. zstyle ':vcs_info:*:prompt:*' nvcsformats ""
  110. zstyle ':prezto:module:git:info' verbose 'yes'
  111. zstyle ':prezto:module:git:info:action' format "${_color_red}! %s"
  112. zstyle ':prezto:module:git:info:added' format "${_color_brightgreen}✚"
  113. zstyle ':prezto:module:git:info:ahead' format "${_color_magenta}▲"
  114. zstyle ':prezto:module:git:info:behind' format "${_color_brightmagenta}▼"
  115. zstyle ':prezto:module:git:info:branch' format "${_color_brightyellow}%b"
  116. zstyle ':prezto:module:git:info:deleted' format "${_color_brightred}✖"
  117. zstyle ':prezto:module:git:info:modified' format "${_color_brightred}✱"
  118. zstyle ':prezto:module:git:info:position' format "${_color_brightwhite}%p"
  119. zstyle ':prezto:module:git:info:renamed' format "${_color_red}►"
  120. zstyle ':prezto:module:git:info:stashed' format "${_color_magenta}s"
  121. zstyle ':prezto:module:git:info:unmerged' format "${_color_red}═"
  122. zstyle ':prezto:module:git:info:untracked' format "${_color_brightblack}?"
  123. # More info on formats at https://github.com/sorin-ionescu/prezto/tree/master/modules/git
  124. zstyle ':prezto:module:git:info:keys' format 'prompt' " ${_color_brightwhite}on ${_color_brightblue}git${_color_brightwhite}:%b %p%A%B%S%a%d%m%r%U%u"
  125. #zstyle ':prezto:module:sys:info:lsb_id' format 'id:-%i-'
  126. #zstyle ':prezto:module:sys:info:lsb_description' format 'desc:-%d-'
  127. #zstyle ':prezto:module:sys:info:lsb_release' format 'rel:-%r-'
  128. #zstyle ':prezto:module:sys:info:lsb_codename' format 'code:-%c-'
  129. #zstyle ':prezto:module:sys:info:uname_all' format 'A:-%A-'
  130. #zstyle ':prezto:module:sys:info:uname_hw' format 'H:-%H-'
  131. #zstyle ':prezto:module:sys:info:uname_kernel_name' format 'K:-%K-'
  132. #zstyle ':prezto:module:sys:info:uname_kernel_release' format 'R:-%R-'
  133. #zstyle ':prezto:module:sys:info:uname_kernel_version' format 'V:-%V-'
  134. #zstyle ':prezto:module:sys:info:uname_machine' format 'M:-%M-'
  135. #zstyle ':prezto:module:sys:info:uname_nodename' format 'N:-%N-'
  136. #zstyle ':prezto:module:sys:info:uname_processor' format 'P:-%P-'
  137. #zstyle ':prezto:module:sys:info:uname_os' format 'O:-%O-'
  138. #zstyle ':prezto:module:sys:info:chroot' format 'CHROOT:-%C-'
  139. #zstyle ':prezto:module:sys:info:ssh_tty' format 'T:-%T-'
  140. #zstyle ':prezto:module:sys:info:ssh_server_address' format 'X:-%X-'
  141. #zstyle ':prezto:module:sys:info:ssh_server_port' format 'Y:-%Y-'
  142. #zstyle ':prezto:module:sys:info:ssh_client_address' format 'x:-%x-'
  143. #zstyle ':prezto:module:sys:info:ssh_client_port' format 'y:-%y-'
  144. #zstyle ':prezto:module:sys:info:keys' format 'prompt' '=%d=%i=%r=%c=%C=%A=%H=%K=%R=%V=%M=%V=%N=%P=%O=%T=%X=%Y=%x=%y'
  145. zstyle ':prezto:module:sys:info:lsb_id' format "${_color_brightblue}%i"
  146. zstyle ':prezto:module:sys:info:lsb_codename' format "${_color_brightblue}%c"
  147. zstyle ':prezto:module:sys:info:chroot' format "${_color_brightred}chroot${_color_brightwhite}:"
  148. zstyle ':prezto:module:sys:info:ssh_tty' format " ${_color_brightwhite}via ${_color_brightred}ssh"
  149. zstyle ':prezto:module:sys:info:keys' format 'prompt' \
  150. "%T ${_color_brightwhite}using %C%i${_color_brightwhite}/%c"
  151. sys-info
  152. # Define prompts.
  153. PROMPT=' \
  154. %(!.%{$_color_brightred%}%n.%{$_color_brightgreen%}%n)\
  155. %{$_color_brightwhite%} at \
  156. %{$_color_brightmagenta%}%m\
  157. %{$_white%}\
  158. %{$_color_brightwhite%} in \
  159. %{$_color_green%}%(!.%d.%~)\
  160. ${git_info[prompt]}\
  161. ${sys_info[prompt]}\
  162. %1(j.%{$_color_brightwhite%} with %{$_color_green%}%j%{$_color_brightwhite%} jobs.)
  163. %0(?..%{$_color_red%}%?)\
  164. %(!.%{$_color_red%}.%{$_color_cyan%})>%{$_color_reset%}'
  165. RPROMPT=''
  166. }
  167. prompt_kolter_setup "$@"