Soliah.zsh-theme 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if hash rvm 2>/dev/null; then
  29. GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
  30. if [[ -n $GEMSET ]]; then
  31. echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
  32. fi
  33. fi
  34. }
  35. # Determine the time since last commit. If branch is clean,
  36. # use a neutral color, otherwise colors will vary according to time.
  37. function git_time_since_commit() {
  38. if git rev-parse --git-dir > /dev/null 2>&1; then
  39. # Only proceed if there is actually a commit.
  40. if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
  41. # Get the last commit.
  42. last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
  43. now=`date +%s`
  44. seconds_since_last_commit=$((now-last_commit))
  45. # Totals
  46. MINUTES=$((seconds_since_last_commit / 60))
  47. HOURS=$((seconds_since_last_commit/3600))
  48. # Sub-hours and sub-minutes
  49. DAYS=$((seconds_since_last_commit / 86400))
  50. SUB_HOURS=$((HOURS % 24))
  51. SUB_MINUTES=$((MINUTES % 60))
  52. if [[ -n $(git status -s 2> /dev/null) ]]; then
  53. if [ "$MINUTES" -gt 30 ]; then
  54. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
  55. elif [ "$MINUTES" -gt 10 ]; then
  56. COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
  57. else
  58. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
  59. fi
  60. else
  61. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  62. fi
  63. if [ "$HOURS" -gt 24 ]; then
  64. echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
  65. elif [ "$MINUTES" -gt 60 ]; then
  66. echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
  67. else
  68. echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
  69. fi
  70. else
  71. COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  72. echo "($(rvm_gemset)$COLOR~|"
  73. fi
  74. fi
  75. }