Soliah.zsh-theme 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 last_commit=`git -c log.showSignature=false log --pretty=format:'%at' -1 2> /dev/null`; then
  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. }