prompt.zsh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 [ $UID = 0 ]; then
  32. export PR_ROOT_PREFIX='*'
  33. else
  34. export PR_ROOT_PREFIX=
  35. fi
  36. function mytitle {
  37. # if running konsole, setting current directory name in tab
  38. [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "${PR_ROOT_PREFIX}${1}"
  39. # if running screen, setting current directory name in caption/statusbar
  40. [ "$TERM" = "screen" ] && echo -ne "\033k${PR_ROOT_PREFIX}${1}\033\\"
  41. # if running 'xterm like' terminal setting directory name in title bar
  42. [ "$TERM" = "xterm" ] && echo -ne "\033]0;${PR_ROOT_PREFIX}${1}\007"
  43. }
  44. function preexec {
  45. binonly=(emacs mplayer lftp most more less rsu)
  46. args=(${=1})
  47. argsr=(${=2})
  48. if [[ $args[0] != $argsr[0] ]]; then
  49. args[0]=$argsr[0]
  50. fi
  51. if [[ -n ${(M)binonly:#$args[0]} ]]; then
  52. args=$args[0]
  53. fi
  54. mytitle "$args"
  55. }
  56. function precmd {
  57. mytitle "$(print -P %~)"
  58. }
  59. myprompt() {
  60. if [ "$TERM" = "dumb" ]; then
  61. PROMPT="-(%n@%m)-(%(!.%d.%~))->"
  62. else
  63. PROMPT='\
  64. $PR_BLUE\
  65. %1(j.-(${PR_YELLOW}jobs:$PR_WHITE%j$PR_BLUE).)\
  66. $PR_BLUE-(\
  67. %(!.$PR_RED%n.$PR_LIGHT_GREEN%n)\
  68. $PR_WHITE@\
  69. $PR_MAGENTA%m$PR_BLUE\
  70. )-(\
  71. $PR_WHITE$PR_OS_NAME$PR_BLUE)-($PR_WHITE%(!.%d.%~)$PR_BLUE)
  72. %0(?..${PR_RED}ret:$PR_WHITE%?$PR_BLUE)>$PR_NO_COLOUR'
  73. fi
  74. }
  75. myprompt