cinaeco.zsh-theme 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ## Set tab title to hostname
  2. print -Pn "\e]1;`hostname | cut -d. -f1`\a"
  3. ## Multiline Prompt
  4. PROMPT='
  5. $(host_name)$(current_folder)$(git_prompt_info)$(background_job_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. ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE=" BEHIND"
  24. ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=" AHEAD"
  25. ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE=" %{$fg[red]%}DIVERGED!"
  26. ##############################
  27. # FUNCTIONS
  28. ##############################
  29. function host_name() {
  30. echo "%{$fg[cyan]%}[%m]"
  31. }
  32. function current_folder() {
  33. echo " %{$fg[yellow]%}%3~"
  34. }
  35. function background_job_info() {
  36. echo " %(1j.%{$FG[063]%}[jobs]: %{$fg[red]%}%j%{$reset_color%}.)"
  37. }
  38. # Display Git repo information in prompt (override the default omz function)
  39. #
  40. # Displays [repo:branch:commit] BISECT/MERGE/REBASE AHEAD/BEHIND/DIVERGED! +±xcrU?
  41. #
  42. # Git commit id and mode code taken from:
  43. # https://github.com/benhoskings/dot-files/blob/master/files/bin/git_cwd_info
  44. function git_prompt_info() {
  45. GIT_REPO_PATH=$(git rev-parse --git-dir 2>/dev/null)
  46. [[ $GIT_REPO_PATH == "" ]] && return
  47. GIT_COMMIT_ID=`git rev-parse --short HEAD 2>/dev/null`
  48. GIT_MODE="%{$fg[magenta]%}"
  49. if [[ -e "$GIT_REPO_PATH/BISECT_LOG" ]]; then
  50. GIT_MODE="$GIT_MODE BISECT"
  51. elif [[ -e "$GIT_REPO_PATH/MERGE_HEAD" ]]; then
  52. GIT_MODE="$GIT_MODE MERGE"
  53. elif [[ -e "$GIT_REPO_PATH/rebase" || -e "$GIT_REPO_PATH/rebase-apply" || -e "$GIT_REPO_PATH/rebase-merge" || -e "$GIT_REPO_PATH/../.dotest" ]]; then
  54. GIT_MODE="$GIT_MODE REBASE"
  55. fi
  56. GIT_STASH=""
  57. if [[ -e "$GIT_REPO_PATH/refs/stash" ]]; then
  58. GIT_STASH=" %{$fg[red]%}STASH"
  59. fi
  60. GIT_BRANCH=$(current_branch)
  61. [[ $GIT_BRANCH == '' ]] && GIT_BRANCH="%{$fg[red]%}no branch$(parse_git_dirty)"
  62. echo " $(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$GIT_BRANCH:$GIT_COMMIT_ID$ZSH_THEME_GIT_PROMPT_SUFFIX$GIT_MODE$(git_remote_status)$GIT_STASH$(git_prompt_status)"
  63. }
  64. # Git Change Indication (overriding default omz function)
  65. #
  66. # Prints symbol for each change instead of just indicating if change type exists.
  67. # This gives a better visual sense of how much has changed.
  68. #
  69. # TODO If you find prompt speed slow, it's because of this section.
  70. # The limitation is the speed of `git status` in any given repo (it's slower
  71. # than you'd imagine).
  72. # This can be countered somewhat by ignoring submodules. We lose reporting of
  73. # submodule changes in prompt, but the speed is much better.
  74. # The rest of the status string building is near-instantaneous.
  75. git_prompt_status() {
  76. local SUBMODULE_SYNTAX=''
  77. [[ $POST_1_7_2_GIT -gt 0 ]] && SUBMODULE_SYNTAX="--ignore-submodules=dirty"
  78. INDEX=$(git status --porcelain $SUBMODULE_SYNTAX 2> /dev/null)
  79. [[ -z $INDEX ]] && return
  80. local X_SET=""
  81. local Y_SET=""
  82. local UN_SET=""
  83. local END=""
  84. local COUNT=0
  85. echo $INDEX | while IFS= read LINE; do
  86. ((COUNT+=1))
  87. ((COUNT >= 20)) && END="%{$reset_color%}..." && break
  88. X=$LINE[1]
  89. Y=$LINE[2]
  90. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  91. [[ $X == 'U' ]] || [[ $Y == 'U' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  92. [[ $X$Y == 'DD' ]] || [[ $X$Y == 'AA' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  93. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  94. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  95. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  96. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  97. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  98. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  99. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  100. done
  101. local STATUS=" %{$FG[070]%}$X_SET%{$FG[124]%}$Y_SET%{$FG[220]%}$UN_SET$END"
  102. echo $STATUS
  103. }
  104. # Read the current repository (override the default omz function)
  105. #
  106. # Cope with non-ssh repos by not relying on ':'. Instead, we look for text
  107. # between a '/' and '.git'.
  108. # TODO should expand to search between '/' and space, if '.git' is not present.
  109. # Some people don't write their remotes properly.
  110. function current_repository() {
  111. echo $(git remote -v | head -1 | sed 's/.*\/\([^/]*\)\.git.*/\1/')
  112. }