Advertisement
Guest User

Untitled

a guest
Jun 28th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. #
  2. # A two-line, Powerline-inspired theme that displays contextual information.
  3. #
  4. # This theme requires a patched Powerline font, get them from
  5. # https://github.com/Lokaltog/powerline-fonts.
  6. #
  7. # Authors:
  8. # Isaac Wolkerstorfer <i@agnoster.net>
  9. # Jeff Sandberg <paradox460@gmail.com>
  10. # Sorin Ionescu <sorin.ionescu@gmail.com>
  11. #
  12. # Screenshots:
  13. # http://i.imgur.com/0XIWX.png
  14. #
  15.  
  16. # Load dependencies.
  17. pmodload 'helper'
  18.  
  19. # Define variables.
  20. _prompt_paradox_current_bg='NONE'
  21. _prompt_paradox_segment_separator=''
  22. _prompt_paradox_start_time=$SECONDS
  23.  
  24. function prompt_paradox_start_segment {
  25. local bg fg
  26. [[ -n "$1" ]] && bg="%K{$1}" || bg="%k"
  27. [[ -n "$2" ]] && fg="%F{$2}" || fg="%f"
  28. if [[ "$_prompt_paradox_current_bg" != 'NONE' && "$1" != "$_prompt_paradox_current_bg" ]]; then
  29. print -n " $bg%F{$_prompt_paradox_current_bg}$_prompt_paradox_segment_separator$fg "
  30. else
  31. print -n "$bg$fg "
  32. fi
  33. _prompt_paradox_current_bg="$1"
  34. [[ -n "$3" ]] && print -n "$3"
  35. }
  36.  
  37. function prompt_paradox_end_segment {
  38. if [[ -n "$_prompt_paradox_current_bg" ]]; then
  39. print -n " %k%F{$_prompt_paradox_current_bg}$_prompt_paradox_segment_separator"
  40. else
  41. print -n "%k"
  42. fi
  43. print -n "%f"
  44. _prompt_paradox_current_bg=''
  45. }
  46.  
  47. function prompt_paradox_build_prompt {
  48. prompt_paradox_start_segment black default '%(?::%F{red}✘ )%(!:%F{yellow}⚡ :)%(1j:%F{cyan}⚙ :)%F{blue}%n%f'
  49. prompt_paradox_start_segment blue black '$_prompt_paradox_pwd'
  50.  
  51. if [[ -n "$git_info" ]]; then
  52. prompt_paradox_start_segment green black '${(e)git_info[ref]}${(e)git_info[status]}'
  53. fi
  54.  
  55. prompt_paradox_end_segment
  56. }
  57.  
  58. function prompt_paradox_pwd {
  59. local pwd="${PWD/#$HOME/~}"
  60.  
  61. if [[ "$pwd" == (#m)[/~] ]]; then
  62. _prompt_paradox_pwd="$MATCH"
  63. unset MATCH
  64. else
  65. _prompt_paradox_pwd="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
  66. fi
  67. }
  68.  
  69. function prompt_paradox_print_elapsed_time {
  70. local end_time=$(( SECONDS - _prompt_paradox_start_time ))
  71. local hours minutes seconds remainder
  72.  
  73. if (( end_time >= 3600 )); then
  74. hours=$(( end_time / 3600 ))
  75. remainder=$(( end_time % 3600 ))
  76. minutes=$(( remainder / 60 ))
  77. seconds=$(( remainder % 60 ))
  78. print -P "%B%F{red}>>> elapsed time ${hours}h${minutes}m${seconds}s%b"
  79. elif (( end_time >= 60 )); then
  80. minutes=$(( end_time / 60 ))
  81. seconds=$(( end_time % 60 ))
  82. print -P "%B%F{yellow}>>> elapsed time ${minutes}m${seconds}s%b"
  83. elif (( end_time > 10 )); then
  84. print -P "%B%F{green}>>> elapsed time ${end_time}s%b"
  85. fi
  86. }
  87.  
  88. function prompt_paradox_precmd {
  89. setopt LOCAL_OPTIONS
  90. unsetopt XTRACE KSH_ARRAYS
  91.  
  92. # Format PWD.
  93. prompt_paradox_pwd
  94.  
  95. # Get Git repository information.
  96. if (( $+functions[git-info] )); then
  97. git-info
  98. fi
  99.  
  100. # Calculate and print the elapsed time.
  101. prompt_paradox_print_elapsed_time
  102. }
  103.  
  104. function prompt_paradox_preexec {
  105. _prompt_paradox_start_time="$SECONDS"
  106. }
  107.  
  108. function prompt_paradox_setup {
  109. setopt LOCAL_OPTIONS
  110. unsetopt XTRACE KSH_ARRAYS
  111. prompt_opts=(cr percent subst)
  112.  
  113. # Load required functions.
  114. autoload -Uz add-zsh-hook
  115.  
  116. # Add hook for calling git-info before each command.
  117. add-zsh-hook preexec prompt_paradox_preexec
  118. add-zsh-hook precmd prompt_paradox_precmd
  119.  
  120. # Set editor-info parameters.
  121. zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
  122. zstyle ':prezto:module:editor:info:keymap:primary' format '%B%F{blue}❯%f%b'
  123. zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format '%F{red}♺%f'
  124. zstyle ':prezto:module:editor:info:keymap:alternate' format '%B%F{red}❮%f%b'
  125.  
  126. # Set git-info parameters.
  127. zstyle ':prezto:module:git:info' verbose 'yes'
  128. zstyle ':prezto:module:git:info:action' format ' ⁝ %s'
  129. zstyle ':prezto:module:git:info:added' format ' ✚'
  130. zstyle ':prezto:module:git:info:ahead' format ' ⬆'
  131. zstyle ':prezto:module:git:info:behind' format ' ⬇'
  132. zstyle ':prezto:module:git:info:branch' format ' %b'
  133. zstyle ':prezto:module:git:info:commit' format '➦ %.7c'
  134. zstyle ':prezto:module:git:info:deleted' format ' ✖'
  135. zstyle ':prezto:module:git:info:dirty' format ' ⁝'
  136. zstyle ':prezto:module:git:info:modified' format ' ✱'
  137. zstyle ':prezto:module:git:info:position' format '%p'
  138. zstyle ':prezto:module:git:info:renamed' format ' ➙'
  139. zstyle ':prezto:module:git:info:stashed' format ' S'
  140. zstyle ':prezto:module:git:info:unmerged' format ' ═'
  141. zstyle ':prezto:module:git:info:untracked' format ' ?'
  142. zstyle ':prezto:module:git:info:keys' format \
  143. 'ref' '$(coalesce "%b" "%p" "%c")' \
  144. 'status' '%s%D%A%B%S%a%d%m%r%U%u'
  145.  
  146. # Define prompts.
  147. PROMPT='
  148. ${(e)$(prompt_paradox_build_prompt)} ${editor_info[keymap]} '
  149. SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
  150. }
  151.  
  152. prompt_paradox_setup "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement