cinaeco.zsh-theme 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ## Set tab title to hostname
  2. print -Pn "\e]1;`hostname | cut -d. -f1`\a"
  3. ## Multiline 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="["
  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_STATUS_MAX=20
  14. ZSH_THEME_GIT_PROMPT_UNMERGED="U"
  15. ZSH_THEME_GIT_PROMPT_UNTRACKED="?"
  16. ZSH_THEME_GIT_TREE_MODIFIED="+"
  17. ZSH_THEME_GIT_TREE_DELETED="x"
  18. ZSH_THEME_GIT_INDEX_MODIFIED="+"
  19. ZSH_THEME_GIT_INDEX_ADDED="±"
  20. ZSH_THEME_GIT_INDEX_DELETED="x"
  21. ZSH_THEME_GIT_INDEX_RENAMED="r"
  22. ZSH_THEME_GIT_INDEX_COPIED="c"
  23. ##############################
  24. # FUNCTIONS
  25. ##############################
  26. # Display Git repo information in prompt (override the default omz function)
  27. #
  28. # Displays [repo_name:branch_name:commit_sha] MERGE/BISECT/REBASE x+changes+x
  29. #
  30. # Git commit id and mode code taken from:
  31. # https://github.com/benhoskings/dot-files/blob/master/files/bin/git_cwd_info
  32. function git_prompt_info() {
  33. GIT_REPO_PATH=$(git rev-parse --git-dir 2>/dev/null)
  34. [[ $GIT_REPO_PATH == "" ]] && return
  35. GIT_COMMIT_ID=`git rev-parse --short HEAD 2>/dev/null`
  36. GIT_MODE=""
  37. if [[ -e "$GIT_REPO_PATH/BISECT_LOG" ]]; then
  38. GIT_MODE=" BISECT"
  39. elif [[ -e "$GIT_REPO_PATH/MERGE_HEAD" ]]; then
  40. GIT_MODE=" MERGE"
  41. elif [[ -e "$GIT_REPO_PATH/rebase" || -e "$GIT_REPO_PATH/rebase-apply" || -e "$GIT_REPO_PATH/rebase-merge" || -e "$GIT_REPO_PATH/../.dotest" ]]; then
  42. GIT_MODE=" REBASE"
  43. fi
  44. GIT_BRANCH=$(current_branch)
  45. [[ $GIT_BRANCH == '' ]] && GIT_BRANCH="%{$fg[red]%}no branch$(parse_git_dirty)"
  46. echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$GIT_BRANCH:$GIT_COMMIT_ID$ZSH_THEME_GIT_PROMPT_SUFFIX%{$fg[magenta]%}$GIT_MODE $(git_prompt_status)"
  47. }
  48. # Git Change Indication (overriding default omz function)
  49. #
  50. # !!ONLY USE WITH MULTILINE PROMPTS!! as there can be a lot of symbols
  51. # (perhaps should limit to 20 or something)
  52. #
  53. # Prints symbol for each change instead of just indicating if a type exists.
  54. # This gives a better visual sense of how much has changed.
  55. #
  56. # TODO If you find prompt speed slow, it's because of this section.
  57. # The limitation is the speed of `git status` in any given repo (it's slower
  58. # than you'd imagine). The rest of the symbol computation is pretty much
  59. # instantaneous, even on older CPUs.
  60. # TODO should we make a way to toggle this on/off on the fly, to deal with
  61. # performance issues for ridiculous git repos?
  62. # TODO number of changes in git repo doesn't necessarily mean slow `git status`,
  63. # neither does it seem to definitely be caused by large number of files. When is
  64. # `git status` slow?
  65. git_prompt_status() {
  66. INDEX=$(git status --porcelain 2> /dev/null)
  67. [[ -z $INDEX ]] && return
  68. X_SET=""
  69. Y_SET=""
  70. UN_SET=""
  71. echo $INDEX | while IFS= read LINE; do
  72. X=$LINE[1]
  73. Y=$LINE[2]
  74. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  75. [[ $X == 'U' ]] || [[ $Y == 'U' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  76. [[ $X$Y == 'DD' ]] || [[ $X$Y == 'AA' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  77. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  78. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  79. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  80. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  81. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  82. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  83. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  84. done
  85. STATUS="%{$FG[070]%}$X_SET%{$FG[124]%}$Y_SET%{$FG[220]%}$UN_SET"
  86. echo $STATUS
  87. }
  88. # Read the current repository (override the default omz function)
  89. #
  90. # Cope with non-ssh repos by not relying on ':'. Instead, we look for text
  91. # between a '/' and '.git'.
  92. # TODO should expand to search between '/' and space, if '.git' is not present.
  93. # Some people don't write their remotes properly.
  94. function current_repository() {
  95. echo $(git remote -v | head -1 | sed 's/.*\/\([^/]*\)\.git.*/\1/')
  96. }