smt.zsh-theme 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -----------------------------------------------------------------------------
  2. # FILE: smt.zsh-theme
  3. # DESCRIPTION: oh-my-zsh theme file, based on dogenpunk by Matthew Nelson.
  4. # AUTHOR: Stephen Tudor (stephen@tudorstudio.com
  5. # VERSION: 0.1
  6. # SCREENSHOT: coming soon
  7. # -----------------------------------------------------------------------------
  8. MODE_INDICATOR="%{$fg_bold[red]%}❮%{$reset_color%}%{$fg[red]%}❮❮%{$reset_color%}"
  9. local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%} "
  10. ZSH_THEME_GIT_PROMPT_PREFIX="|"
  11. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
  12. ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%}⚡%{$reset_color%}"
  13. ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[red]%}!%{$reset_color%}"
  14. ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
  15. ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} ✚"
  16. ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} ✹"
  17. ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✖"
  18. ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜"
  19. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═"
  20. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭"
  21. # Format for git_prompt_long_sha() and git_prompt_short_sha()
  22. ZSH_THEME_GIT_PROMPT_SHA_BEFORE="➤ %{$fg_bold[yellow]%}"
  23. ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$reset_color%}"
  24. function prompt_char() {
  25. git branch >/dev/null 2>/dev/null && echo "%{$fg[green]%}±%{$reset_color%}" && return
  26. hg root >/dev/null 2>/dev/null && echo "%{$fg_bold[red]%}☿%{$reset_color%}" && return
  27. echo "%{$fg[cyan]%}◯%{$reset_color%}"
  28. }
  29. # Colors vary depending on time lapsed.
  30. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
  31. ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
  32. ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
  33. ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
  34. # Determine the time since last commit. If branch is clean,
  35. # use a neutral color, otherwise colors will vary according to time.
  36. function git_time_since_commit() {
  37. if git rev-parse --git-dir > /dev/null 2>&1; then
  38. # Only proceed if there is actually a commit.
  39. if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
  40. # Get the last commit.
  41. last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
  42. now=`date +%s`
  43. seconds_since_last_commit=$((now-last_commit))
  44. # Totals
  45. MINUTES=$((seconds_since_last_commit / 60))
  46. HOURS=$((seconds_since_last_commit/3600))
  47. # Sub-hours and sub-minutes
  48. DAYS=$((seconds_since_last_commit / 86400))
  49. SUB_HOURS=$((HOURS % 24))
  50. SUB_MINUTES=$((MINUTES % 60))
  51. if [[ -n $(git status -s 2> /dev/null) ]]; then
  52. if [ "$MINUTES" -gt 30 ]; then
  53. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
  54. elif [ "$MINUTES" -gt 10 ]; then
  55. COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
  56. else
  57. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
  58. fi
  59. else
  60. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  61. fi
  62. if [ "$HOURS" -gt 24 ]; then
  63. echo "[$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}]"
  64. elif [ "$MINUTES" -gt 60 ]; then
  65. echo "[$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}]"
  66. else
  67. echo "[$COLOR${MINUTES}m%{$reset_color%}]"
  68. fi
  69. else
  70. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  71. echo "[$COLOR~]"
  72. fi
  73. fi
  74. }
  75. PROMPT='
  76. %{$fg[blue]%}%m%{$reset_color%} 福 %{$fg[cyan]%}%~ %{$reset_color%}$(git_prompt_short_sha)$(git_prompt_info)
  77. %{$fg[red]%}%!%{$reset_color%} $(prompt_char) : '
  78. RPROMPT='${return_status}$(git_time_since_commit)$(git_prompt_status)%{$reset_color%}'