adben.zsh-theme 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env zsh
  2. # #
  3. # # #README
  4. # #
  5. # # This theme provides two customizable header functionalities:
  6. # # a) displaying a pseudo-random message from a database of quotations
  7. # # (https://en.wikipedia.org/wiki/Fortune_%28Unix%29)
  8. # # b) displaying randomly command line tips from The command line fu
  9. # # (http://www.commandlinefu.com) community: in order to make use of this functionality
  10. # # you will need Internet connection.
  11. # # This theme provides as well information for the current user's context, like;
  12. # # branch and status for the current version control system (git and svn currently
  13. # # supported) and time, presented to the user in a non invasive volatile way.
  14. # #
  15. # # #REQUIREMENTS
  16. # # This theme requires wget::
  17. # # -Homebrew-osx- brew install wget
  18. # # -Debian/Ubuntu- apt-get install wget
  19. # # and fortune ::
  20. # # -Homebrew-osx- brew install fortune
  21. # # -Debian/Ubuntu- apt-get install fortune
  22. # #
  23. # # optionally:
  24. # # -Oh-myzsh vcs plug-ins git and svn.
  25. # # -Solarized theme (https://github.com/altercation/solarized/)
  26. # # -OS X: iTerm 2 (http://www.iterm2.com/)
  27. # # -font Source code pro (https://github.com/adobe/source-code-pro)
  28. # #
  29. # # This theme's look and feel is based on the Aaron Toponce's zsh theme, more info:
  30. # # http://pthree.org/2008/11/23/727/
  31. # # enjoy!
  32. ########## COLOR ###########
  33. for COLOR in CYAN WHITE YELLOW MAGENTA BLACK BLUE RED DEFAULT GREEN GREY; do
  34. eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
  35. eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
  36. done
  37. PR_RESET="%{$reset_color%}"
  38. RED_START="${PR_RESET}${PR_GREY}<${PR_RESET}${PR_RED}<${PR_BRIGHT_RED}<${PR_RESET} "
  39. RED_END="${PR_RESET}${PR_BRIGHT_RED}>${PR_RESET}${PR_RED}>${PR_GREY}>${PR_RESET} "
  40. GREEN_END="${PR_RESET}${PR_BRIGHT_GREEN}>${PR_RESET}${PR_GREEN}>${PR_GREY}>${PR_RESET} "
  41. GREEN_BASE_START="${PR_RESET}${PR_GREY}>${PR_RESET}${PR_GREEN}>${PR_BRIGHT_GREEN}>${PR_RESET}"
  42. GREEN_START_P1="${PR_RESET}${GREEN_BASE_START}${PR_RESET} "
  43. DIVISION="${PR_RESET}${PR_RED} < ${PR_RESET}"
  44. VCS_DIRTY_COLOR="${PR_RESET}${PR_YELLOW}"
  45. Vcs_CLEAN_COLOR="${PR_RESET}${PR_GREEN}"
  46. VCS_SUFIX_COLOR="${PR_RESET}${PR_RED}› ${PR_RESET}"
  47. # ########## COLOR ###########
  48. # ########## SVN ###########
  49. ZSH_THEME_SVN_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹svn:"
  50. ZSH_THEME_SVN_PROMPT_SUFFIX=""
  51. ZSH_THEME_SVN_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘${VCS_SUFIX_COLOR}"
  52. ZSH_THEME_SVN_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔${VCS_SUFIX_COLOR}"
  53. # ########## SVN ###########
  54. # ########## GIT ###########
  55. ZSH_THEME_GIT_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹git:"
  56. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  57. ZSH_THEME_GIT_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘${VCS_SUFIX_COLOR}"
  58. ZSH_THEME_GIT_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔${VCS_SUFIX_COLOR}"
  59. ZSH_THEME_GIT_PROMPT_ADDED="${PR_RESET}${PR_YELLOW} ✚${PR_RESET}"
  60. ZSH_THEME_GIT_PROMPT_MODIFIED="${PR_RESET}${PR_YELLOW} ✹${PR_RESET}"
  61. ZSH_THEME_GIT_PROMPT_DELETED="${PR_RESET}${PR_YELLOW} ✖${PR_RESET}"
  62. ZSH_THEME_GIT_PROMPT_RENAMED="${PR_RESET}${PR_YELLOW} ➜${PR_RESET}"
  63. ZSH_THEME_GIT_PROMPT_UNMERGED="${PR_RESET}${PR_YELLOW} ═${PR_RESET}"
  64. ZSH_THEME_GIT_PROMPT_UNTRACKED="${PR_RESET}${PR_YELLOW} ✭${PR_RESET}"
  65. # ########## GIT ###########
  66. function precmd {
  67. #gets the fortune
  68. ps1_fortune () {
  69. #Choose from all databases, regardless of whether they are considered "offensive"
  70. fortune -a
  71. }
  72. #obtains the tip
  73. ps1_command_tip () {
  74. wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed 1d | sed '/^$/d'
  75. }
  76. prompt_header () {
  77. if [[ "true" == "$ENABLE_COMMAND_TIP" ]]; then
  78. ps1_command_tip
  79. else
  80. ps1_fortune
  81. fi
  82. }
  83. PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}"
  84. # set a simple variable to show when in screen
  85. if [[ -n "${WINDOW}" ]]; then
  86. SCREEN=""
  87. fi
  88. }
  89. # Context: user@directory or just directory
  90. prompt_context () {
  91. if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
  92. echo -n "${PR_RESET}${PR_RED}$USER@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  93. else
  94. echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  95. fi
  96. }
  97. set_prompt () {
  98. # required for the prompt
  99. setopt prompt_subst
  100. autoload zsh/terminfo
  101. # ######### PROMPT #########
  102. PROMPT='${PROMPT_HEAD}
  103. ${RED_START}$(prompt_context)
  104. ${GREEN_START_P1}'
  105. RPROMPT='${PR_RESET}$(git_prompt_info)$(svn_prompt_info)${PR_YELLOW}%D{%R.%S %a %b %d %Y} ${GREEN_END}${PR_RESET}'
  106. # Matching continuation prompt
  107. PROMPT2='${GREEN_BASE_START}${PR_RESET} %_ ${GREEN_BASE_START}${PR_RESET} '
  108. # ######### PROMPT #########
  109. }
  110. set_prompt