prompt.zsh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # prompt config
  2. setopt prompt_subst
  3. # enable colors
  4. autoload colors zsh/terminfo
  5. if [[ "$terminfo[colors]" -ge 8 ]]; then
  6. colors
  7. fi
  8. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  9. eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  10. eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  11. done
  12. PR_NO_COLOUR="%{$terminfo[sgr0]%}"
  13. export PR_OS_NAME=$(uname -s)
  14. export PR_OS_ARCH=$(uname -m)
  15. if [ -f /etc/debian_version ]; then
  16. if [ "$PR_OS_NAME" = "Linux" ]; then
  17. PR_OS_NAME="debian $(</etc/debian_version)"
  18. else
  19. PR_OS_NAME="debian/${PR_OS_NAME} $(</etc/debian_version)"
  20. fi
  21. if [ -f /etc/debian_chroot ]; then
  22. PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$(</etc/debian_version)"
  23. fi
  24. fi
  25. PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
  26. if [ "$TERM" = "screen" -a -n "$WINDOW" ]; then
  27. export PR_OS_PTY="scr/$WINDOW"
  28. else
  29. export PR_OS_PTY=$(print -P %l)
  30. fi
  31. if [ -n "$SSH_CLIENT" ]; then
  32. export PR_OS_SSH="${PR_LIGHT_RED}ssh:"
  33. else
  34. export PR_OS_SSH=
  35. fi
  36. if [ $UID = 0 ]; then
  37. export PR_ROOT_PREFIX='*'
  38. else
  39. export PR_ROOT_PREFIX=
  40. fi
  41. function mytitle {
  42. # if running konsole, setting current directory name in tab
  43. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "${PR_ROOT_PREFIX}${1}"
  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