cinaeco.zsh-theme 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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="["
  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. ## Override the default `git_prompt_info` function
  27. ## Git commit id and mode code taken from:
  28. ## https://github.com/benhoskings/dot-files/blob/master/files/bin/git_cwd_info
  29. function git_prompt_info() {
  30. GIT_REPO_PATH=$(git rev-parse --git-dir 2>/dev/null)
  31. [[ $GIT_REPO_PATH == "" ]] && return
  32. GIT_COMMIT_ID=`git rev-parse --short HEAD 2>/dev/null`
  33. GIT_MODE=""
  34. if [[ -e "$GIT_REPO_PATH/BISECT_LOG" ]]; then
  35. GIT_MODE=" BISECT"
  36. elif [[ -e "$GIT_REPO_PATH/MERGE_HEAD" ]]; then
  37. GIT_MODE=" MERGE"
  38. elif [[ -e "$GIT_REPO_PATH/rebase" || -e "$GIT_REPO_PATH/rebase-apply" || -e "$GIT_REPO_PATH/rebase-merge" || -e "$GIT_REPO_PATH/../.dotest" ]]; then
  39. GIT_MODE=" REBASE"
  40. fi
  41. GIT_BRANCH=$(current_branch)
  42. [[ $GIT_BRANCH == '' ]] && GIT_BRANCH="%{$fg[red]%}no branch$(parse_git_dirty)"
  43. 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)"
  44. }
  45. ## Override the default `git_prompt_status` function
  46. ## Preferably only use with multiline prompts
  47. ## Try to print a each change instead of just indicating if each type exists.
  48. ## This gives a better visual sense of how much has changed
  49. ## Status is computed from the short version of git status that lists out
  50. ## xy filename1
  51. ## xy filename2
  52. ## where x and y are statuses such as A (added), M (modified). Details in the
  53. ## git-status manpage.
  54. ## TODO Is this as fast as it gets? Maybe. The speed of this script appears to
  55. ## be limited by the speed of --porcelain or -s in any given repo.
  56. git_prompt_status() {
  57. INDEX=$(git status --porcelain 2> /dev/null)
  58. [[ -z $INDEX ]] && return
  59. X_SET=""
  60. Y_SET=""
  61. UN_SET=""
  62. echo $INDEX | while IFS= read LINE; do
  63. X=$LINE[1]
  64. Y=$LINE[2]
  65. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  66. [[ $X == 'U' ]] || [[ $Y == 'U' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  67. [[ $X$Y == 'DD' ]] || [[ $X$Y == 'AA' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  68. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  69. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  70. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  71. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  72. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  73. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  74. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  75. done
  76. STATUS="%{$FG[070]%}$X_SET%{$FG[124]%}$Y_SET%{$FG[220]%}$UN_SET"
  77. echo $STATUS
  78. }
  79. ## Override the default `current_repository` function
  80. ## Cope with non-ssh repos by not relying on ':'. Instead, we look for text
  81. ## between a '/' and '.git'.
  82. ##
  83. ## We don't need to test if HEAD is a symbolic ref - that gets controlled in
  84. ## git_prompt_info(). Unlike `current_branch` there are no oh-my-zsh shortcuts
  85. ## that will be broken if we don't test for this.
  86. function current_repository() {
  87. echo $(git remote -v | head -1 | sed 's/.*\/\([^/]*\)\.git.*/\1/')
  88. }