magicmace.zsh-theme 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. # magicmace theme
  3. # Ideas and code taken from:
  4. # xero's zsh prompt <http://code.xero.nu/dotfiles>
  5. # eriner's eriner prompt <https://github.com/zimfw/zimfw/blob/master/modules/prompt/themes/eriner.zsh-theme>
  6. #
  7. # Requires the `git-info` zmodule to be included in the .zimrc file.
  8. # Global variables
  9. function {
  10. COLOR_ROOT="%F{red}"
  11. COLOR_USER="%F{cyan}"
  12. COLOR_NORMAL="%F{white}"
  13. COLOR_ERROR="%F{red}"
  14. if (( ${EUID} )); then
  15. COLOR_USER_LEVEL=${COLOR_USER}
  16. else
  17. COLOR_USER_LEVEL=${COLOR_ROOT}
  18. fi
  19. }
  20. # Status:
  21. # - was there an error?
  22. # - are there background jobs?
  23. # - are we in a ranger session?
  24. prompt_magicmace_status() {
  25. local symbols=""
  26. (( ${RETVAL} )) && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error.
  27. (( $(jobs -l | wc -l) > 0 )) && symbols+='b' # 'b' for background.
  28. (( ${RANGER_LEVEL} )) && symbols+='r' # 'r' for... you guessed it!
  29. [[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─"
  30. }
  31. prompt_magicmace_git() {
  32. [[ -n ${git_info} ]] && print -n "${(e)git_info[prompt]}"
  33. }
  34. prompt_magicmace_precmd() {
  35. # While it would be apt to have this as a local variable in prompt_status(),
  36. # $? (returned value) and ${(%):-%?} ("The return status of the last command
  37. # executed just before the prompt") both change before executing the function.
  38. # Is this perhaps because prompt_status _is_ here?
  39. # We could also just set $? as an argument, and thus get our nifty local variable,
  40. # but that's stretching it, and makes the code harder to read.
  41. RETVAL=$?
  42. (( ${+functions[git-info]} )) && git-info
  43. }
  44. prompt_magicmace_setup() {
  45. autoload -Uz colors && colors
  46. autoload -Uz add-zsh-hook
  47. prompt_opts=(cr percent sp subst)
  48. add-zsh-hook precmd prompt_magicmace_precmd
  49. zstyle ':zim:git-info:branch' format '%b'
  50. zstyle ':zim:git-info:commit' format '%c...'
  51. zstyle ':zim:git-info:dirty' format '*'
  52. zstyle ':zim:git-info:ahead' format '↑'
  53. zstyle ':zim:git-info:behind' format '↓'
  54. zstyle ':zim:git-info:keys' format \
  55. 'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]'
  56. # Call git directly, ignoring aliases under the same name.
  57. PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f '
  58. RPROMPT=''
  59. }
  60. prompt_magicmace_setup "$@"