smt.zsh-theme 3.2 KB

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