Soliah.zsh-theme 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(check_git_prompt_info)
  2. $ '
  3. ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
  4. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
  5. # Text to display if the branch is dirty
  6. ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
  7. # Text to display if the branch is clean
  8. ZSH_THEME_GIT_PROMPT_CLEAN=""
  9. # Colors vary depending on time lapsed.
  10. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
  11. ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
  12. ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
  13. ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
  14. # Git sometimes goes into a detached head state. git_prompt_info doesn't
  15. # return anything in this case. So wrap it in another function and check
  16. # for an empty string.
  17. function check_git_prompt_info() {
  18. if git rev-parse --git-dir > /dev/null 2>&1; then
  19. if [[ -z $(git_prompt_info) ]]; then
  20. echo "%{$fg[magenta]%}detached-head%{$reset_color%})"
  21. else
  22. echo "$(git_prompt_info)"
  23. fi
  24. fi
  25. }
  26. # Determine if we are using a gemset.
  27. function rvm_gemset() {
  28. GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
  29. if [[ -n $GEMSET ]]; then
  30. echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
  31. fi
  32. }
  33. # Determine the time since last commit. If branch is clean,
  34. # use a neutral color, otherwise colors will vary according to time.
  35. function git_time_since_commit() {
  36. if git rev-parse --git-dir > /dev/null 2>&1; then
  37. # Only proceed if there is actually a commit.
  38. if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
  39. # Get the last commit.
  40. last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
  41. now=`date +%s`
  42. seconds_since_last_commit=$((now-last_commit))
  43. # Totals
  44. MINUTES=$((seconds_since_last_commit / 60))
  45. HOURS=$((seconds_since_last_commit/3600))
  46. # Sub-hours and sub-minutes
  47. DAYS=$((seconds_since_last_commit / 86400))
  48. SUB_HOURS=$((HOURS % 24))
  49. SUB_MINUTES=$((MINUTES % 60))
  50. if [[ -n $(git status -s 2> /dev/null) ]]; then
  51. if [ "$MINUTES" -gt 30 ]; then
  52. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
  53. elif [ "$MINUTES" -gt 10 ]; then
  54. COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
  55. else
  56. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
  57. fi
  58. else
  59. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  60. fi
  61. if [ "$HOURS" -gt 24 ]; then
  62. echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
  63. elif [ "$MINUTES" -gt 60 ]; then
  64. echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
  65. else
  66. echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
  67. fi
  68. else
  69. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  70. echo "($(rvm_gemset)$COLOR~|"
  71. fi
  72. fi
  73. }