essembeh.zsh-theme 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # My custom theme:
  2. # - single line
  3. # - quite simple by default: user@host:$PWD
  4. # - green for local shell as non root
  5. # - red for ssh shell as non root
  6. # - magenta for root sessions
  7. # - prefix with remote address for ssh shells
  8. # - prefix to detect docker containers or chroot
  9. # - git plugin to display current branch and status
  10. # git plugin
  11. ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}("
  12. ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}"
  13. ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
  14. ZSH_THEME_GIT_PROMPT_ADDED="+"
  15. ZSH_THEME_GIT_PROMPT_MODIFIED="*"
  16. ZSH_THEME_GIT_PROMPT_RENAMED="~"
  17. ZSH_THEME_GIT_PROMPT_DELETED="!"
  18. ZSH_THEME_GIT_PROMPT_UNMERGED="?"
  19. function zsh_essembeh_gitstatus {
  20. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  21. GIT_STATUS=$(git_prompt_status)
  22. if [[ -n $GIT_STATUS ]]; then
  23. GIT_STATUS=" $GIT_STATUS"
  24. fi
  25. echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
  26. }
  27. # by default, use green for user@host and no prefix
  28. local ZSH_ESSEMBEH_COLOR="green"
  29. local ZSH_ESSEMBEH_PREFIX=""
  30. if [[ -n "$SSH_CONNECTION" ]]; then
  31. # display the source address if connected via ssh
  32. ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} "
  33. # use red color to highlight a remote connection
  34. ZSH_ESSEMBEH_COLOR="red"
  35. elif [[ -r /etc/debian_chroot ]]; then
  36. # prefix prompt in case of chroot
  37. ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} "
  38. elif [[ -r /.dockerenv ]]; then
  39. # also prefix prompt inside a docker container
  40. ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[docker]%{$reset_color%} "
  41. fi
  42. if [[ $UID = 0 ]]; then
  43. # always use magenta for root sessions, even in ssh
  44. ZSH_ESSEMBEH_COLOR="magenta"
  45. fi
  46. PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}%n@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) '
  47. RPROMPT="%(?..%{$fg[red]%}%?%{$reset_color%})"