adben.zsh-theme 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. # # Author: Adolfo Benedetti
  30. # # email: adolfo.benedetti@gmail.com
  31. # # License: Public Domain
  32. # # This theme's look and feel is based on the Aaron Toponce's zsh theme , more info:
  33. # # http://pthree.org/2008/11/23/727/
  34. # # enjoy!
  35. ########## COLOR ###########
  36. for COLOR in CYAN WHITE YELLOW MAGENTA BLACK BLUE RED DEFAULT GREEN GREY; do
  37. eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
  38. eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
  39. done
  40. PR_RESET="%{$reset_color%}"
  41. RED_START="${PR_RESET}${PR_GREY}<${PR_RESET}${PR_RED}<${PR_BRIGHT_RED}<${PR_RESET} "
  42. RED_END="${PR_RESET}${PR_BRIGHT_RED}>${PR_RESET}${PR_RED}>${PR_GREY}>${PR_RESET} "
  43. GREEN_END="${PR_RESET}${PR_BRIGHT_GREEN}>${PR_RESET}${PR_GREEN}>${PR_GREY}>${PR_RESET} "
  44. GREEN_BASE_START="${PR_RESET}${PR_GREY}>${PR_RESET}${PR_GREEN}>${PR_BRIGHT_GREEN}>${PR_RESET}"
  45. GREEN_START_P1="${PR_RESET}${GREEN_BASE_START}${PR_RESET} "
  46. DIVISION="${PR_RESET}${PR_RED} < ${PR_RESET}"
  47. VCS_DIRTY_COLOR="${PR_RESET}${PR_YELLOW}"
  48. Vcs_CLEAN_COLOR="${PR_RESET}${PR_GREEN}"
  49. VCS_SUFIX_COLOR="${PR_RESET}${PR_RED}› ${PR_RESET}"
  50. # ########## COLOR ###########
  51. # ########## SVN ###########
  52. ZSH_THEME_SVN_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹svn:"
  53. ZSH_THEME_SVN_PROMPT_SUFFIX=""
  54. ZSH_THEME_SVN_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘${VCS_SUFIX_COLOR}"
  55. ZSH_THEME_SVN_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔${VCS_SUFIX_COLOR}"
  56. # ########## SVN ###########
  57. # ########## GIT ###########
  58. ZSH_THEME_GIT_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹git:"
  59. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  60. ZSH_THEME_GIT_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘${VCS_SUFIX_COLOR}"
  61. ZSH_THEME_GIT_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔${VCS_SUFIX_COLOR}"
  62. ZSH_THEME_GIT_PROMPT_ADDED="${PR_RESET}${PR_YELLOW} ✚${PR_RESET}"
  63. ZSH_THEME_GIT_PROMPT_MODIFIED="${PR_RESET}${PR_YELLOW} ✹${PR_RESET}"
  64. ZSH_THEME_GIT_PROMPT_DELETED="${PR_RESET}${PR_YELLOW} ✖${PR_RESET}"
  65. ZSH_THEME_GIT_PROMPT_RENAMED="${PR_RESET}${PR_YELLOW} ➜${PR_RESET}"
  66. ZSH_THEME_GIT_PROMPT_UNMERGED="${PR_RESET}${PR_YELLOW} ═${PR_RESET}"
  67. ZSH_THEME_GIT_PROMPT_UNTRACKED="${PR_RESET}${PR_YELLOW} ✭${PR_RESET}"
  68. # ########## GIT ###########
  69. function precmd {
  70. #gets the fortune
  71. ps1_fortune () {
  72. #Choose from all databases, regardless of whether they are considered "offensive"
  73. fortune -a
  74. }
  75. #obtains the tip
  76. ps1_command_tip () {
  77. wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed 1d | sed '/^$/d'
  78. }
  79. prompt_header () {
  80. if [[ "true" == "$ENABLE_COMMAND_TIP" ]]; then
  81. ps1_command_tip
  82. else
  83. ps1_fortune
  84. fi
  85. }
  86. PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}"
  87. # set a simple variable to show when in screen
  88. if [[ -n "${WINDOW}" ]]; then
  89. SCREEN=""
  90. fi
  91. }
  92. # Context: user@directory or just directory
  93. prompt_context () {
  94. local user=`whoami`
  95. if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
  96. echo -n "${PR_RESET}${PR_RED}$user@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  97. else
  98. echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  99. fi
  100. }
  101. set_prompt () {
  102. # required for the prompt
  103. setopt prompt_subst
  104. autoload colors zsh/terminfo
  105. if [[ "$terminfo[colors]" -gt 8 ]]; then
  106. colors
  107. fi
  108. # ######### PROMPT #########
  109. PROMPT='${PROMPT_HEAD}
  110. ${RED_START}$(prompt_context)
  111. ${GREEN_START_P1}'
  112. RPROMPT='${PR_RESET}$(git_prompt_info)$(svn_prompt_info)${PR_YELLOW}%D{%R.%S %a %b %d %Y} ${GREEN_END}${PR_RESET}'
  113. # Matching continuation prompt
  114. PROMPT2='${GREEN_BASE_START}${PR_RESET} %_ ${GREEN_BASE_START}${PR_RESET} '
  115. # ######### PROMPT #########
  116. }
  117. set_prompt