prompt.zsh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_COLOUR="%{$terminfo[sgr0]%}"
  15. export PR_OS_NAME=$(uname -s)
  16. export PR_OS_ARCH=$(uname -m)
  17. if [ -f /etc/debian_version ]; then
  18. # ugly way to detect Ubuntu chroots
  19. LSB_NAME=$(egrep 'DISTRIB_(ID|CODENAME)' /etc/lsb-release 2>/dev/null \
  20. | tr '\n' '=' | cut -d'=' -f2,4 | tr '=' ' ')
  21. if [ "$PR_OS_NAME" = "Linux" ]; then
  22. PR_OS_NAME="Debian $(</etc/debian_version)"
  23. else
  24. PR_OS_NAME="Debian/${PR_OS_NAME} $(</etc/debian_version)"
  25. fi
  26. if [ -f /etc/debian_chroot ]; then
  27. if [ -n "$LSB_NAME" ]; then
  28. PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$LSB_NAME"
  29. else
  30. PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}Debian $(</etc/debian_version)"
  31. fi
  32. else
  33. if [ -n "$LSB_NAME" ]; then
  34. PR_OS_NAME="$LSB_NAME"
  35. fi
  36. fi
  37. unset LSB_NAME
  38. fi
  39. PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
  40. if [ "$TERM" = "screen" -a -n "$WINDOW" ]; then
  41. export PR_OS_PTY="scr/$WINDOW"
  42. else
  43. export PR_OS_PTY=$(print -P %l)
  44. fi
  45. if [ -n "$SSH_CLIENT" ]; then
  46. export PR_OS_SSH="${PR_LIGHT_RED}ssh:"
  47. else
  48. export PR_OS_SSH=
  49. fi
  50. if [ "$UID" = 0 ]; then
  51. export PR_ROOT_PREFIX='*'
  52. else
  53. export PR_ROOT_PREFIX=
  54. fi
  55. function mytitle {
  56. # if running screen, setting current directory name in caption/statusbar
  57. [ "$TERM" = "screen" ] && echo -ne "\033k${PR_ROOT_PREFIX}${1}\033\\"
  58. # if running 'xterm like' terminal setting directory name in title bar
  59. [ "$TERM" = "xterm" ] && echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
  60. }
  61. function preexec {
  62. local -a buffer
  63. buffer=(${=1})
  64. mytitle "$buffer[1]"
  65. }
  66. function precmd {
  67. mytitle "$(print -P %~)"
  68. }
  69. myprompt() {
  70. if [ "$TERM" = "dumb" ]; then
  71. PROMPT="-(%n@%m)-(%(!.%d.%~))->"
  72. else
  73. PROMPT='\
  74. ${PR_BLUE}\
  75. %1(j.-(${PR_YELLOW}jobs:${PR_WHITE}%j${PR_BLUE}).)\
  76. ${PR_BLUE}-(\
  77. %(!.${PR_RED}%n.${PR_LIGHT_GREEN}%n)\
  78. ${PR_WHITE}@${PR_OS_SSH}${PR_MAGENTA}%m${PR_WHITE} ${PR_OS_PTY}${PR_BLUE})-(\
  79. ${PR_WHITE}${PR_OS_NAME}${PR_BLUE})-(${PR_WHITE}%(!.%d.%~)${PR_BLUE})
  80. %0(?..${PR_RED}ret:${PR_WHITE}%?${PR_BLUE})>${PR_NO_COLOUR}'
  81. fi
  82. }
  83. myprompt