cinaeco.zsh-theme 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="[git:"
  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. ## We decide if we show nothing, status with no branch (like in submodules) or
  28. ## with a branch using regex comparisons.
  29. ## Is there a better way than relying on error output?
  30. function git_prompt_info() {
  31. ref=$(git symbolic-ref HEAD 2>&1)
  32. [[ $ref =~ "Not a git" ]] && return
  33. [[ $ref =~ "not a symbolic" ]] && echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):%{$fg[red]%}no branch$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)" && return
  34. echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)"
  35. }
  36. ## Override the default `git_prompt_status` function
  37. ## Preferably only use with multiline prompts
  38. ## Try to print a each change instead of just indicating if each type exists.
  39. ## This gives a better visual sense of how much has changed
  40. ## Status is computed from the short version of git status that lists out
  41. ## xy filename1
  42. ## xy filename2
  43. ## where x and y are statuses such as A (added), M (modified). Details in the
  44. ## git-status manpage.
  45. ## TODO Is this as fast as it gets? Maybe. The speed of this script appears to
  46. ## be limited by the speed of --porcelain or -s in any given repo.
  47. git_prompt_status() {
  48. INDEX=$(git status --porcelain 2> /dev/null)
  49. [[ -z $INDEX ]] && return
  50. X_SET=""
  51. Y_SET=""
  52. UN_SET=""
  53. echo $INDEX | while IFS= read LINE; do
  54. X=$LINE[1]
  55. Y=$LINE[2]
  56. [[ $X$Y == '??' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNTRACKED" && continue
  57. [[ $X == 'U' ]] || [[ $Y == 'U' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  58. [[ $X$Y == 'DD' ]] || [[ $X$Y == 'AA' ]] && UN_SET="$UN_SET$ZSH_THEME_GIT_PROMPT_UNMERGED" && continue
  59. [[ $Y == 'M' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_MODIFIED"
  60. [[ $Y == 'D' ]] && Y_SET="$Y_SET$ZSH_THEME_GIT_TREE_DELETED"
  61. [[ $X == 'M' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_MODIFIED" && continue
  62. [[ $X == 'A' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_ADDED" && continue
  63. [[ $X == 'D' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_DELETED" && continue
  64. [[ $X == 'R' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_RENAMED" && continue
  65. [[ $X == 'C' ]] && X_SET="$X_SET$ZSH_THEME_GIT_INDEX_COPIED" && continue
  66. done
  67. STATUS="%{$FG[070]%}$X_SET%{$FG[124]%}$Y_SET%{$FG[220]%}$UN_SET"
  68. echo $STATUS
  69. }
  70. ## Override the default `current_repository` function
  71. ## Cope with non-ssh repos by not relying on ':'. Instead, we look for text
  72. ## between a '/' and '.git'.
  73. ##
  74. ## We don't need to test if HEAD is a symbolic ref - that gets controlled in
  75. ## git_prompt_info(). Unlike `current_branch` there are no oh-my-zsh shortcuts
  76. ## that will be broken if we don't test for this.
  77. function current_repository() {
  78. echo $(git remote -v | head -1 | sed 's/.*\/\([^/]*\)\.git.*/\1/')
  79. }