cinaeco.zsh-theme 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ## Set tab title to hostname
  2. print -Pn "\e]1;`hostname | cut -d. -f1`\a"
  3. ## multi line prompt
  4. PROMPT='
  5. %{$fg[cyan]%}[%m] %{$fg[yellow]%}%3~ $(git_prompt_info)
  6. %{$fg[magenta]%}%n → %{$reset_color%}'
  7. RPROMPT='$(vi_mode_prompt_info) %{$reset_color%}%T %{$fg[white]%}%h%{$reset_color%}'
  8. MODE_INDICATOR="%{$fg[green]%}vi-mode%{$reset_color%}"
  9. ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
  10. ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
  11. ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
  12. ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}"
  13. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$FG[226]%}U"
  14. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$FG[220]%}?"
  15. ZSH_THEME_GIT_TREE_MODIFIED="%{$FG[124]%}+"
  16. ZSH_THEME_GIT_TREE_DELETED="%{$FG[124]%}x"
  17. ZSH_THEME_GIT_INDEX_MODIFIED="%{$FG[070]%}+"
  18. ZSH_THEME_GIT_INDEX_ADDED="%{$FG[070]%}+"
  19. ZSH_THEME_GIT_INDEX_DELETED="%{$FG[070]%}x"
  20. ZSH_THEME_GIT_INDEX_RENAMED="%{$FG[070]%}r"
  21. ZSH_THEME_GIT_INDEX_COPIED="%{$FG[070]%}c"
  22. ##############################
  23. # FUNCTIONS
  24. ##############################
  25. ## Override the default `git_prompt_info` function
  26. ## We decide if we show nothing, status with no branch (like in submodules) or
  27. ## with a branch using regex comparisons.
  28. ## Is there a better way than relying on error output?
  29. function git_prompt_info() {
  30. ref=$(git symbolic-ref HEAD 2>&1)
  31. [[ $ref =~ "Not a git" ]] && return
  32. [[ $ref =~ "not a symbolic" ]] && echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):%{$fg[red]%}no branch$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)" && return
  33. echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)"
  34. }
  35. ## Override the default `git_prompt_status` function
  36. ## Try to print a each change instead of just indicating if each type exists.
  37. ## This gives a better visual sense of how much has changed
  38. ## Status is computed from the short version of git status that lists out
  39. ## xy filename1
  40. ## xy filename2
  41. ## where x and y are statuses such as A (added), M (modified). Details in the
  42. ## git-status manpage.
  43. ## Is this as fast as it gets?
  44. git_prompt_status() {
  45. INDEX=$(git status -s 2> /dev/null)
  46. X_SET=""
  47. Y_SET=""
  48. UN_SET=""
  49. echo $INDEX | while IFS= read LINE; do
  50. X=$LINE[1]
  51. Y=$LINE[2]
  52. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  53. [[ $X$Y == 'UU' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  54. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  55. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  56. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  57. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  58. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  59. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  60. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  61. done
  62. STATUS="$X_SET$Y_SET$UN_SET"
  63. echo $STATUS
  64. }
  65. ## Override the default `current_repository` function
  66. ## Cope with non-ssh repos by not relying on ':'. Instead, we look for the name
  67. ## suffixed with .git
  68. ##
  69. ## We don't need to test if HEAD is a symbolic ref - that gets controlled in
  70. ## git_prompt_info(). Unlike `current_branch` there are no oh-my-zsh shortcuts
  71. ## that will be broken if we don't test for this.
  72. ## Is there another way? 4 pipelines seems excessive
  73. function current_repository() {
  74. echo $(git remote -v | head -1 | grep -o '[^/]*\.git' | sed 's/\.git//')
  75. }