prompt_peepcode_setup 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #
  2. # A simple theme from PeepCode.
  3. # http://peepcode.com/blog/2012/my-command-line-prompt
  4. #
  5. # Authors:
  6. # Geoffrey Grosenbach <boss@topfunky.com>
  7. # Sorin Ionescu <sorin.ionescu@gmail.com>
  8. #
  9. # Screenshots:
  10. # http://i.imgur.com/LhgmW.png
  11. #
  12. function prompt_peepcode_precmd {
  13. # Get Git repository information.
  14. if (( $+functions[git-info] )); then
  15. git-info
  16. fi
  17. # Get Ruby information.
  18. if (( $+functions[ruby-info] )); then
  19. ruby-info
  20. fi
  21. }
  22. function prompt_peepcode_setup {
  23. setopt LOCAL_OPTIONS
  24. unsetopt XTRACE KSH_ARRAYS
  25. prompt_opts=(cr percent sp subst)
  26. # Load required functions.
  27. autoload -Uz add-zsh-hook
  28. autoload -Uz vcs_info
  29. # Add a hook for calling info functions before each command.
  30. add-zsh-hook precmd prompt_peepcode_precmd
  31. # Tell prezto we can manage this prompt
  32. zstyle ':prezto:module:prompt' managed 'yes'
  33. # Set git-info parameters.
  34. zstyle ':prezto:module:git:info' verbose 'no'
  35. zstyle ':prezto:module:git:info:action' format ' +%s'
  36. zstyle ':prezto:module:git:info:branch' format ' %F{8}%b%f'
  37. zstyle ':prezto:module:git:info:commit' format ' %F{white}%.7c%f'
  38. zstyle ':prezto:module:git:info:indexed' format ' '
  39. zstyle ':prezto:module:git:info:unindexed' format ' '
  40. zstyle ':prezto:module:git:info:untracked' format ' '
  41. zstyle ':prezto:module:git:info:dirty' format ' %F{8}✗%f'
  42. zstyle ':prezto:module:git:info:keys' format 'rprompt' '%b%c%s%D'
  43. # Set ruby-info parameters.
  44. zstyle ':prezto:module:ruby:info:version' format ' %F{white}%v%f'
  45. # Define prompts.
  46. PROMPT="
  47. %~
  48. %(?.%F{green}${1:-☻ }%f.%F{red}${1:-☻ }%f) "
  49. RPROMPT='${ruby_info[version]}${git_info[rprompt]}'
  50. }
  51. function prompt_peepcode_help {
  52. cat <<EOH
  53. This prompt's last command exit status symbol is customizable:
  54. prompt peepcode [<symbol>]
  55. If this option is not provided, the symbol defaults to ☻.
  56. EOH
  57. }
  58. function prompt_peepcode_preview {
  59. local +h PROMPT='%# '
  60. local +h RPROMPT=''
  61. local +h SPROMPT=''
  62. if (( $# > 0 )); then
  63. prompt_preview_theme 'peepcode' "$@"
  64. else
  65. prompt_preview_theme 'peepcode'
  66. print
  67. prompt_preview_theme 'peepcode' "❯"
  68. print
  69. prompt_preview_theme 'peepcode' "$"
  70. fi
  71. }
  72. prompt_peepcode_setup "$@"
  73. # vim: ft=zsh