michelebologna.zsh-theme 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Michele Bologna's theme
  2. # https://www.michelebologna.net
  3. #
  4. # This a theme for oh-my-zsh. Features a colored prompt with:
  5. # * username@host: [jobs] [git] workdir %
  6. # * hostname color is based on hostname characters. When using as root, the
  7. # prompt shows only the hostname in red color.
  8. # * [jobs], if applicable, counts the number of suspended jobs tty
  9. # * [git], if applicable, represents the status of your git repo (more on that
  10. # later)
  11. # * '%' prompt will be green if last command return value is 0, yellow otherwise.
  12. #
  13. # git prompt is inspired by official git contrib prompt:
  14. # https://github.com/git/git/tree/master/contrib/completion/git-prompt.sh
  15. # and it adds:
  16. # * the current branch
  17. # * '%' if there are untracked files
  18. # * '$' if there are stashed changes
  19. # * '*' if there are modified files
  20. # * '+' if there are added files
  21. # * '<' if local repo is behind remote repo
  22. # * '>' if local repo is ahead remote repo
  23. # * '=' if local repo is equal to remote repo (in sync)
  24. # * '<>' if local repo is diverged
  25. local green="%{$fg_bold[green]%}"
  26. local red="%{$fg_bold[red]%}"
  27. local cyan="%{$fg_bold[cyan]%}"
  28. local yellow="%{$fg_bold[yellow]%}"
  29. local blue="%{$fg_bold[blue]%}"
  30. local magenta="%{$fg_bold[magenta]%}"
  31. local white="%{$fg_bold[white]%}"
  32. local reset="%{$reset_color%}"
  33. local -a color_array
  34. color_array=($green $red $cyan $yellow $blue $magenta $white)
  35. local username_color=$white
  36. local hostname_color=$color_array[$[((#HOST))%7+1]] # choose hostname color based on first character
  37. local current_dir_color=$blue
  38. local username="%n"
  39. local hostname="%m"
  40. local current_dir="%~"
  41. local username_output="%(!..${username_color}${username}${reset}@)"
  42. local hostname_output="${hostname_color}${hostname}${reset}"
  43. local current_dir_output="${current_dir_color}${current_dir}${reset}"
  44. local jobs_bg="${red}fg: %j$reset"
  45. local last_command_output="%(?.%(!.$red.$green).$yellow)"
  46. ZSH_THEME_GIT_PROMPT_PREFIX=""
  47. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  48. ZSH_THEME_GIT_PROMPT_DIRTY=""
  49. ZSH_THEME_GIT_PROMPT_CLEAN=""
  50. ZSH_THEME_GIT_PROMPT_UNTRACKED="$blue%%"
  51. ZSH_THEME_GIT_PROMPT_MODIFIED="$red*"
  52. ZSH_THEME_GIT_PROMPT_ADDED="$green+"
  53. ZSH_THEME_GIT_PROMPT_STASHED="$blue$"
  54. ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="$green="
  55. ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
  56. ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
  57. ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>"
  58. function michelebologna_git_prompt {
  59. local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status)
  60. [[ -n $out ]] || return
  61. printf " %s(%s%s%s)%s" \
  62. "%{$fg_bold[white]%}" \
  63. "%{$fg_bold[green]%}" \
  64. "$out" \
  65. "%{$fg_bold[white]%}" \
  66. "%{$reset_color%}"
  67. }
  68. PROMPT="$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)"
  69. PROMPT+='$(michelebologna_git_prompt)'
  70. PROMPT+=" $last_command_output%#$reset "
  71. RPROMPT=''