2
0

emotty.zsh-theme 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env zsh
  2. # ------------------------------------------------------------------------------
  3. # FILE: emotty.zsh-theme
  4. # DESCRIPTION: A varying emoji based theme
  5. # AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net)
  6. # VERSION: 1.0.0
  7. # DEPENDS: emotty plugin
  8. # RECOMMENDS: Hasklig font
  9. #
  10. # This theme shows a different emoji for each tty at the main prompt.
  11. #
  12. # There are pre-defined different emoji sets to choose from, e.g.:
  13. # emoji, stellar, floral, zodiac, love (see emotty plugin).
  14. #
  15. # To choose a different emotty set than the default (emoji)
  16. # % export emotty_set=nature
  17. #
  18. # For the superuser (root) this theme shows a designated indicator
  19. # and switches the foreground color to red
  20. # (see root_prompt variable, default: skull).
  21. # But you are using sudo (8) instead of designated a root shell, right‽
  22. #
  23. # When logged in via SSH the main prompt also shows the user- and hostname.
  24. #
  25. # The exit status of the last failed command is displayed in the window title
  26. # along with an indicator (see warn_glyph variable, default: collision symbol).
  27. # To clear it just run: $NULL, true or :
  28. #
  29. # The right prompt shows the current working directory (3 levels up) in cyan.
  30. #
  31. # When in a git repository the main prompt shows the current branch name
  32. # with a branch indicator in yellow
  33. # (see vcs_branch_glyph variable, default: Hasklig branch glyph).
  34. #
  35. # If there are modified files the prompt switches to red and shows an unstaged
  36. # indicator (see vcs_unstaged_glyph variable, default: circled letter M).
  37. #
  38. # If there are staged files the prompt switches to green and shows an staged
  39. # indicator (see vcs_staged_glyph variable, default: high voltage sign).
  40. #
  41. # In a git repository the right prompt shows the repository name in bold and
  42. # prepends the current working directory subpath within the repository.
  43. #
  44. # When git currently performs an action such as merge or rebase, the action is
  45. # displayed in red instead of the branch name and a special action indicator
  46. # is shown (see vcs_action_glyph variable, default: chevron).
  47. # ------------------------------------------------------------------------------
  48. (( ${+functions[emotty]} )) || {
  49. echo "error: the emotty theme requires the emotty plugin" >&2
  50. return 1
  51. }
  52. (( ${+emoji} )) || {
  53. echo "error: the emotty theme requires the emoji plugin" >&2
  54. return 1
  55. }
  56. user_prompt="$(emotty)"
  57. root_prompt="$emoji[skull]"
  58. warn_prompt="$emoji[collision_symbol]"
  59. vcs_unstaged_glyph="%{$emoji[circled_latin_capital_letter_m]$emoji2[emoji_style] %2G%}"
  60. vcs_staged_glyph="%{$emoji[high_voltage_sign]%2G%}"
  61. vcs_branch_glyph=$'\Ue0a0' # 
  62. vcs_action_glyph=$'\U276f' # ❯
  63. red="$FG[001]"
  64. yellow="$FG[003]"
  65. green="$FG[002]"
  66. cyan="$FG[014]"
  67. prompt_glyph="%{%(#.${root_prompt}.${user_prompt}) %2G%}"
  68. # Uncomment the next line if you also like to see the warn_prompt in the prompt on the right.
  69. #last_command_failed="%(?.. %F{red}%1{${warn_prompt} %1G%}%?%f)"
  70. setopt promptsubst
  71. # Workaround for zsh 5.2 release (kudos to @timothybasanov)
  72. autoload +X VCS_INFO_nvcsformats
  73. functions[VCS_INFO_nvcsformats]=${functions[VCS_INFO_nvcsformats]/local -a msgs/}
  74. autoload -U add-zsh-hook
  75. autoload -Uz vcs_info
  76. zstyle ':vcs_info:*' enable git #hg svn cvs
  77. zstyle ':vcs_info:*' get-revision false
  78. zstyle ':vcs_info:*' check-for-changes true
  79. zstyle ':vcs_info:git:*' unstagedstr "${red}${vcs_unstaged_glyph}"
  80. zstyle ':vcs_info:*' stagedstr "${green}${vcs_staged_glyph}"
  81. # %(K|F){color} set (back|fore)ground color
  82. # %(k|f) reset (back|fore)ground color
  83. zstyle ':vcs_info:*' max-exports 3
  84. zstyle ':vcs_info:*' nvcsformats "${prompt_glyph}" '%3~' ''
  85. zstyle ':vcs_info:*' formats "${yellow}%u%c%b${vcs_branch_glyph}%f" '%S|' "$FX[bold]%r$FX[no-bold]"
  86. zstyle ':vcs_info:*' actionformats "${red}%K{white}%a${vcs_action_glyph}%k%f" '%S|' "$FX[bold]%r$FX[no-bold]"
  87. red_if_root="%(!.%F{red}.)"
  88. sshuser_on_host="${SSH_TTY:+%(!.$red.$yellow)%n@%m$reset_color}"
  89. PROMPT='${sshuser_on_host}${vcs_info_msg_0_}${red_if_root} '
  90. RPROMPT='${cyan}${vcs_info_msg_1_##.|}${vcs_info_msg_2_}%f${last_command_failed}'
  91. emotty_title() {
  92. title "${${?/[^0]*/$warn_prompt $?}/0/${prompt_glyph}}"
  93. }
  94. add-zsh-hook precmd emotty_title
  95. add-zsh-hook precmd vcs_info
  96. # vim:ft=zsh ts=2 sw=2 sts=2