prompt.zsh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # Prompt config
  3. #
  4. setopt prompt_subst
  5. # enable colors
  6. autoload colors zsh/terminfo
  7. if [[ "$terminfo[colors]" -ge 8 ]]; then
  8. colors
  9. fi
  10. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  11. eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  12. eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  13. done
  14. PR_NO_COLOR="%{$terminfo[sgr0]%}"
  15. export PR_OS_NAME=$(uname -s)
  16. export PR_OS_ARCH=$(uname -m)
  17. if [ -f /etc/debian_version ]; then
  18. PR_OS_NAME="$(lsb_release -is)/$(lsb_release -cs)"
  19. if [ -f /etc/debian_chroot ]; then
  20. PR_OS_NAME="${PR_LIGHT_RED}chroot:${PR_WHITE}${PR_OS_NAME}"
  21. fi
  22. fi
  23. PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
  24. if [ -n "$SSH_CLIENT" ]; then
  25. export PR_OS_SSH="${PR_LIGHT_RED}ssh:"
  26. else
  27. export PR_OS_SSH=
  28. fi
  29. if [ "$UID" = 0 ]; then
  30. export PR_ROOT_PREFIX='*'
  31. else
  32. export PR_ROOT_PREFIX=
  33. fi
  34. function mytitle {
  35. # if running 'xterm like' terminal setting directory name in title bar
  36. if [ "$TERM" = "xterm" ]; then
  37. echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
  38. fi
  39. }
  40. function preexec {
  41. local -a buffer
  42. buffer=(${=1})
  43. mytitle "$buffer[1]"
  44. }
  45. function precmd {
  46. mytitle "$(print -P %~)"
  47. }
  48. myprompt() {
  49. if [ "$TERM" = "dumb" ]; then
  50. PROMPT="-(%n@%m)-(%(!.%d.%~))->"
  51. else
  52. PROMPT='\
  53. ${PR_BLUE}\
  54. %1(j.-(${PR_YELLOW}jobs:${PR_WHITE}%j${PR_BLUE}).)\
  55. ${PR_BLUE}-(\
  56. %(!.${PR_RED}%n.${PR_LIGHT_GREEN}%n)\
  57. ${PR_WHITE}@${PR_OS_SSH}${PR_MAGENTA}%m${PR_WHITE} ${PR_OS_PTY}${PR_BLUE})-(\
  58. ${PR_WHITE}${PR_OS_NAME}${PR_BLUE})-(${PR_WHITE}%(!.%d.%~)${PR_BLUE})
  59. %0(?..${PR_RED}ret:${PR_WHITE}%?${PR_BLUE})>${PR_NO_COLOR}'
  60. fi
  61. }
  62. myprompt