avit.zsh-theme 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #
  2. # Author:: Andrew Vit (<andrew@avit.ca>)
  3. #
  4. # AVIT ZSH Theme
  5. #
  6. # Copyright 2011, Andrew Vit
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. PROMPT='
  21. $(_user_host)${_current_dir} $(git_prompt_info) $(_ruby_version)
  22. ▶ '
  23. PROMPT2='%{$fg[grey]%}◀%{$reset_color%} '
  24. RPROMPT='$(_vi_status)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
  25. local _current_dir="%{$fg[blue]%}%3~%{$reset_color%} "
  26. local _return_status="%{$fg[red]%}%(?..⍉)%{$reset_color%}"
  27. local _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
  28. function _user_host() {
  29. if [[ -n $SSH_CONNECTION ]]; then
  30. me="%n@%m"
  31. elif [[ $LOGNAME != $USER ]]; then
  32. me="%n"
  33. fi
  34. if [[ -n $me ]]; then
  35. echo "%{$fg[cyan]%}$me%{$reset_color%}:"
  36. fi
  37. }
  38. function _vi_status() {
  39. if {echo $fpath | grep -q "plugins/vi-mode"}; then
  40. echo "$(vi_mode_prompt_info)"
  41. fi
  42. }
  43. function _ruby_version() {
  44. if {echo $fpath | grep -q "plugins/rvm"}; then
  45. echo "%{$fg[grey]%}$(rvm_prompt_info)%{$reset_color%}"
  46. fi
  47. }
  48. # Determine the time since last commit. If branch is clean,
  49. # use a neutral color, otherwise colors will vary according to time.
  50. function _git_time_since_commit() {
  51. if git rev-parse --git-dir > /dev/null 2>&1; then
  52. # Only proceed if there is actually a commit.
  53. if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
  54. # Get the last commit.
  55. last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null)
  56. now=$(date +%s)
  57. seconds_since_last_commit=$((now-last_commit))
  58. # Totals
  59. minutes=$((seconds_since_last_commit / 60))
  60. hours=$((seconds_since_last_commit/3600))
  61. # Sub-hours and sub-minutes
  62. days=$((seconds_since_last_commit / 86400))
  63. sub_hours=$((hours % 24))
  64. sub_minutes=$((minutes % 60))
  65. if [ $hours -gt 24 ]; then
  66. commit_age="${days}d"
  67. elif [ $minutes -gt 60 ]; then
  68. commit_age="${sub_hours}h${sub_minutes}m"
  69. else
  70. commit_age="${minutes}m"
  71. fi
  72. color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL
  73. echo "$color$commit_age%{$reset_color%}"
  74. fi
  75. fi
  76. }
  77. if [[ $USER == "root" ]]; then
  78. CARETCOLOR="red"
  79. else
  80. CARETCOLOR="white"
  81. fi
  82. MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}"
  83. ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
  84. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
  85. ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}"
  86. ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}"
  87. ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚ "
  88. ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%}⚑ "
  89. ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}✖ "
  90. ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}▴ "
  91. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ "
  92. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%}◒ "
  93. # Colors vary depending on time lapsed.
  94. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
  95. ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
  96. ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
  97. ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[grey]%}"
  98. # LS colors, made with http://geoff.greer.fm/lscolors/
  99. export LSCOLORS="exfxcxdxbxegedabagacad"
  100. export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
  101. export GREP_COLOR='1;33'