prompt.zsh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if [ "$PR_OS_NAME" = "Linux" ]; then
  19. PR_OS_NAME="debian $(</etc/debian_version)"
  20. else
  21. PR_OS_NAME="debian/${PR_OS_NAME} $(</etc/debian_version)"
  22. fi
  23. if [ -f /etc/debian_chroot ]; then
  24. PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$(</etc/debian_version)"
  25. fi
  26. fi
  27. PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
  28. if [ "$TERM" = "screen" -a -n "$WINDOW" ]; then
  29. export PR_OS_PTY="scr/$WINDOW"
  30. else
  31. export PR_OS_PTY=$(print -P %l)
  32. fi
  33. if [ -n "$SSH_CLIENT" ]; then
  34. export PR_OS_SSH="${PR_LIGHT_RED}ssh:"
  35. else
  36. export PR_OS_SSH=
  37. fi
  38. if [ "$UID" = 0 ]; then
  39. export PR_ROOT_PREFIX='*'
  40. else
  41. export PR_ROOT_PREFIX=
  42. fi
  43. function mytitle {
  44. # if running screen, setting current directory name in caption/statusbar
  45. [ "$TERM" = "screen" ] && echo -ne "\033k${PR_ROOT_PREFIX}${1}\033\\"
  46. # if running 'xterm like' terminal setting directory name in title bar
  47. [ "$TERM" = "xterm" ] && echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
  48. }
  49. function preexec {
  50. local -a buffer
  51. buffer=(${=1})
  52. mytitle "$buffer[1]"
  53. }
  54. function precmd {
  55. mytitle "$(print -P %~)"
  56. }
  57. myprompt() {
  58. if [ "$TERM" = "dumb" ]; then
  59. PROMPT="-(%n@%m)-(%(!.%d.%~))->"
  60. else
  61. PROMPT='\
  62. ${PR_BLUE}\
  63. %1(j.-(${PR_YELLOW}jobs:${PR_WHITE}%j${PR_BLUE}).)\
  64. ${PR_BLUE}-(\
  65. %(!.${PR_RED}%n.${PR_LIGHT_GREEN}%n)\
  66. ${PR_WHITE}@${PR_OS_SSH}${PR_MAGENTA}%m${PR_WHITE} ${PR_OS_PTY}${PR_BLUE})-(\
  67. ${PR_WHITE}${PR_OS_NAME}${PR_BLUE})-(${PR_WHITE}%(!.%d.%~)${PR_BLUE})
  68. %0(?..${PR_RED}ret:${PR_WHITE}%?${PR_BLUE})>${PR_NO_COLOUR}'
  69. fi
  70. }
  71. myprompt