cinaeco.zsh-theme 4.4 KB

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