michelebologna.zsh-theme 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 reset="%{$reset_color%}"
  32. local -a color_array
  33. color_array=($green $red $cyan $yellow $blue $magenta)
  34. local username_color=$blue
  35. local hostname_color=$color_array[$[((#HOST))%6+1]] # choose hostname color based on first character
  36. local current_dir_color=$blue
  37. local username="%n"
  38. local hostname="%m"
  39. local current_dir="%~"
  40. local username_output="%(!..${username_color}${username}${reset}@)"
  41. local hostname_output="${hostname_color}${hostname}${reset}"
  42. local current_dir_output="${current_dir_color}${current_dir}${reset}"
  43. local jobs_bg="${red}fg: %j$reset"
  44. local last_command_output="%(?.%(!.$red.$green).$yellow)"
  45. ZSH_THEME_GIT_PROMPT_PREFIX=""
  46. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  47. ZSH_THEME_GIT_PROMPT_DIRTY=""
  48. ZSH_THEME_GIT_PROMPT_CLEAN=""
  49. ZSH_THEME_GIT_PROMPT_UNTRACKED="$blue%%"
  50. ZSH_THEME_GIT_PROMPT_MODIFIED="$red*"
  51. ZSH_THEME_GIT_PROMPT_ADDED="$green+"
  52. ZSH_THEME_GIT_PROMPT_STASHED="$blue$"
  53. ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="$green="
  54. ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
  55. ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
  56. ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>"
  57. function michelebologna_git_prompt {
  58. local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status)
  59. [[ -n $out ]] || return
  60. printf " %s(%s%s%s)%s" \
  61. "%{$fg_bold[blue]%}" \
  62. "%{$fg_bold[green]%}" \
  63. "$out" \
  64. "%{$fg_bold[blue]%}" \
  65. "%{$reset_color%}"
  66. }
  67. PROMPT="$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)"
  68. PROMPT+='$(michelebologna_git_prompt)'
  69. PROMPT+=" $last_command_output%#$reset "
  70. RPROMPT=''