cinaeco.zsh-theme 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. DISABLE_UNTRACKED_FILES_DIRTY="false"
  27. ##############################
  28. # FUNCTIONS
  29. ##############################
  30. function host_name() {
  31. echo "%{$fg[cyan]%}[%m]"
  32. }
  33. function current_folder() {
  34. echo " %{$fg[yellow]%}%3~"
  35. }
  36. function background_job_info() {
  37. echo " %(1j.%{$FG[063]%}[jobs]: %{$fg[red]%}%j%{$reset_color%}.)"
  38. }
  39. # Set Up List of Git Status Indicators
  40. #
  41. # This function retrieves a porcelain `git status` for use in other functions,
  42. # `git_prompt_status` and `parse_git_dirty`.
  43. get_git_status() {
  44. local FLAGS
  45. FLAGS=("--porcelain")
  46. [[ $POST_1_7_2_GIT -gt 0 ]] && FLAGS+="--ignore-submodules=dirty"
  47. [[ $DISABLE_UNTRACKED_FILES_DIRTY == "true" ]] && FLAGS+="--untracked-files=no"
  48. INDEX=$(git status $FLAGS 2> /dev/null)
  49. }
  50. # Display Git repo information in prompt (override the default omz function)
  51. #
  52. # Displays [repo:branch:commit] BISECT/MERGE/REBASE AHEAD/BEHIND/DIVERGED! +±xcrU?
  53. #
  54. # Git commit id and mode code taken from:
  55. # https://github.com/benhoskings/dot-files/blob/master/files/bin/git_cwd_info
  56. function git_prompt_info() {
  57. local GIT_REPO_PATH=$(git rev-parse --git-dir 2>/dev/null)
  58. [[ $GIT_REPO_PATH == "" ]] && return
  59. local GIT_COMMIT_ID=`git rev-parse --short HEAD 2>/dev/null`
  60. local GIT_MODE="%{$fg[magenta]%}"
  61. if [[ -e "$GIT_REPO_PATH/BISECT_LOG" ]]; then
  62. GIT_MODE="$GIT_MODE BISECT"
  63. elif [[ -e "$GIT_REPO_PATH/MERGE_HEAD" ]]; then
  64. GIT_MODE="$GIT_MODE MERGE"
  65. elif [[ -e "$GIT_REPO_PATH/rebase" || -e "$GIT_REPO_PATH/rebase-apply" || -e "$GIT_REPO_PATH/rebase-merge" || -e "$GIT_REPO_PATH/../.dotest" ]]; then
  66. GIT_MODE="$GIT_MODE REBASE"
  67. fi
  68. local GIT_STASH=""
  69. if [[ -e "$GIT_REPO_PATH/refs/stash" ]]; then
  70. GIT_STASH=" %{$fg[red]%}STASH"
  71. fi
  72. get_git_status
  73. echo " $(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$(current_branch):$GIT_COMMIT_ID$ZSH_THEME_GIT_PROMPT_SUFFIX$GIT_MODE$(git_remote_status)$GIT_STASH$(git_prompt_status)"
  74. }
  75. # Git Change Indication (overriding default omz function)
  76. #
  77. # Prints symbol for each change instead of just indicating if change type exists.
  78. # This gives a better visual sense of how much has changed.
  79. #
  80. # As big as it looks, this function's status-string building is
  81. # near-instantaneous. It's just string manipulation after all.
  82. #
  83. # If you find prompt speed slow, it's because of the speed of `git status` in
  84. # any given repo: it's slower than you'd imagine.
  85. git_prompt_status() {
  86. [[ -z $INDEX ]] && return
  87. local X
  88. local Y
  89. local X_SET=""
  90. local Y_SET=""
  91. local UN_SET=""
  92. local END=""
  93. local COUNT=0
  94. echo $INDEX | while IFS= read LINE; do
  95. ((COUNT+=1))
  96. ((COUNT >= 20)) && END="%{$reset_color%}..." && break
  97. X=$LINE[1]
  98. Y=$LINE[2]
  99. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  100. [[ $X == 'U' ]] || [[ $Y == 'U' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  101. [[ $X$Y == 'DD' ]] || [[ $X$Y == 'AA' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  102. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  103. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  104. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  105. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  106. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  107. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  108. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  109. done
  110. local STATUS=" %{$FG[070]%}$X_SET%{$FG[124]%}$Y_SET%{$FG[220]%}$UN_SET$END"
  111. echo $STATUS
  112. }
  113. # Read the current repository (override the default omz function)
  114. #
  115. # Cope with non-ssh repos by not relying on ':'. Instead, we look for text
  116. # between a '/' and whitespace. '.git' is removed.
  117. function current_repository() {
  118. local repo=$(git remote -v | head -1 | sed 's/.*\/\([^/]*\)\ .*/\1/')
  119. echo ${repo%.git}
  120. }
  121. # Check if a repo is modified (override the default omz function)
  122. #
  123. # This function is modifed to no longer run `git status`, and to instead rely on
  124. # the output of the single invocation in `get_git_status`. This way, we
  125. # hopefully reduce the time taken to produce a prompt in messy repos.
  126. parse_git_dirty() {
  127. if [[ -n $INDEX ]]; then
  128. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  129. else
  130. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  131. fi
  132. }